Giter VIP home page Giter VIP logo

Comments (1)

emanuele6 avatar emanuele6 commented on July 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.