Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use jq to remove top level module while retaining values

I’m trying to use jq in order to achieve the following –

With an input of:

{
    "SomeValue": {
        "x" : "y",
        "a" : "b"
    }
}

I’d like to be able to remove ‘SomeValue’ and return just the key/values below so that my output would look like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    "x" : "y",
    "a" : "b"
}

I’ve tried various permutations of commands I’ve seen on the forum but either end up deleting the whole structure or nothing at all – thanks in advance for any help/pointers in the right direction.

>Solution :

If all you want is the content of .SomeValue, that’s already exactly your filter:

jq '.SomeValue'

If this part is nested deeper, and you want to update that part while keeping the rest, use the update operator |= with .SomeValue on that context (with your small sample this is still just .):

jq '. |= SomeValue'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading