Comments (1)
It's hard to understand your question because it is not very clear what exactly you want to do. Do the JSON objects come from different files? From another JSON object? Do you want to remove both duplicates or keep one? Do you prefer keeping the id from the first object over the second object, or viceversa, or does it not matter?
Also because your example is not valid JSON (], [
), and in one object the expiration days are a "180"
string and in the other a 180
numbers, etc.
Anyway, comparing objects ignoring the value of ID
is pretty straight forward, you can use a combination of the del/1
function and the unique_by/1
function to do this.
For example, if you have multiple files containing those objects with just a Rules
entry and nothing else, and you want to output, a single object with a Rules
entry that contains the union of all the Rules
, and you don't care about the order of the rules in the output, and if there are duplicates ignoring ID
you want to keep only one duplicate (not preferring the ID from a file over another), you would just use:
jq -s 'map(.Rules[]) | { Rules: unique_by(del(.ID)) }' -- file1.json file2.json file3.json
If that does not match your use case, feel free to provide more details.
from jq.
Related Issues (20)
- need command line options to print path and key values of JSON file HOT 7
- Please add nullish coalescing operator "??" to JQ? HOT 3
- Cannot select sub-field that has a dash in the name of the field HOT 1
- compile error HOT 10
- Multiplying -1 with 0 must result 0, not -0 HOT 2
- ~/.jq is not sourced on windows
- Unexpected output HOT 1
- Null bytes are handled inconsistently HOT 5
- tonumber doesn't work on `true` or `false` HOT 4
- "color for object keys" from JQ_COLORS doesn't seem to be respected HOT 4
- `range/3` behaviour when $init and $upto arguments are not numbers HOT 4
- Regular expression alternation (|) used with quantifier (* or +) returns inconsistent results when first alternative is able to match an empty string HOT 3
- Create Multi Smaller Files From a Big Json File HOT 5
- Add the Symbolic Binding Operator ("as") to the operator priority table HOT 1
- Including and importing module with importing JSON crashes jq
- The code example for trim ltrim and rtrim from the manual do not work HOT 2
- Incorrect `Invalid path expression` in destructuring expressions
- 1.7.1 dumps core on Cygwin, trying to find the input filename to print an error message HOT 5
- jq --raw modes, --binary and newlines
- Request for snap maintenance HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jq.