Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQ delete multiple properties

Tags:

json

jq

I have an object like this:

{
    "a" : 1,
    "b" : {
        "c" : {
            "c1" : "abc",
            "source" : "abcxyz"
        },
        "d" : {
            "d1" : "abcd",
            "source" : "abcxyz"
        },
        "e" : {
            "e1" : "abcde",
            "source" : "abcxyz"
        }
    }
}

My expectation is

{
    "a" : 1,
    "b" : {
        "c" : {
            "c1" : "abc"
        },
        "d" : {
            "d1" : "abcd"
        },
        "e" : {
            "e1" : "abcde"
        }
    }
}

I want to remove "source" properties. How can I do that without specifying keys "c", "d" or "e", because they are dynamic.

like image 565
Vu Le Anh Avatar asked Jul 28 '16 03:07

Vu Le Anh


1 Answers

Here is another solution

del( .b[].source )
like image 128
jq170727 Avatar answered Oct 09 '22 01:10

jq170727