Home > OS >  Use jq to remove top level module while retaining values
Use jq to remove top level module while retaining values

Time:10-07

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:

{
    "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.

CodePudding user response:

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'
  • Related