Resolved: delete from one object those entries matching another object based off string id

In this post, we will see how to resolve delete from one object those entries matching another object based off string id

Question:

So, given two files with JSON data from the same source type. The JSON objects look something like:
file1:
file2:
I’m trying to remove objects in the array in the first file with the matching IDs in the second file so that the resultant output would be:
I’ve tried a bunch of ways to accomplish this, but I haven’t found a proper solution yet.
A couple of attempts have been various permutations of the following with accompanying errors:
Ideally it would be super cool to do some kind of operation like:
(kinda Ruby-ish like would be cool) and I admit, I haven’t tried this but I will for kicks and giggles.
I’m trying not to have to use a function and I want to accomplish this using jq. I’m probably not too far off, but I’m at a loss. Any thoughts?

Best Answer:

You could compile a list of IDs from the second file using input, check against it using IN, and either use del to delete the matching, or map to keep those that do not match:
or
If you can assert that objects with identical IDs also are identical in their other parts, and you don’t have many items (because it’s costly), you can even just subtract the second file from the first:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com