I have a json file in which I wish to retrieve all the paths of all the keys.
I have been using JQ, however, it does not show the paths which have null as their values. What am I missing here?
Json :
{
"Root": [
{
"id1": "val",
"id2": "val",
"id3": null,
"id4": 1,
"id5": null,
"id6": "val",
"id7": {
"id8": "val",
"id9": "val",
"id10": null,
"id11": "val"
}
}
]
}
jq -r 'paths(scalars) as $p | [ ( [ $p[] | tostring ] | join(".") ), ( getpath($p) | tojson )] | join(": ")' test_data.json
Output is as shown as
{
"Root": [
{
"id1": "val",
"id2": "val",
"id3": null,
"id4": 1,
"id5": null,
"id6": "val",
"id7": {
"id8": "val",
"id9": "val",
"id10": null,
"id11": "val"
}
}
]
}
I wish to see path of the all nodes including those which have null as their value.
question from:
https://stackoverflow.com/questions/65947125/jq-fetch-all-the-paths-in-json-including-null-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…