example data.json file:
{
"JSON_KEY": {
"SOME_TITLE": {
"RANDOM_STRING1": {
"label": "value",
"units": {
"subunits": [
{"item1": "1", "item2": "2"},
{"item3": "3", "item4":"4"}
]
}
}
}
}
}
Imagine this structure. RANDOM_STRING1 is the first random string in a file with hundreds, maybe thousands, of random strings. There is only one JSON key here.
I tried searching and the closest I've found got me with the following command, found from another stackoverflow post. This command will strip the first parts and leave me with the RANDOM_STRING. but, it includes all it's objects and lists.
jq -r '.[] | [.[]]' data.json
result:
[
{
"RANDOM_STRING1": {
"label": "value",
"units": {
"subunits": [
{
"item1": "1",
"item2": "2"
},
{
"item3": "3",
"item4": "4"
}
]
}
}
}
]
I need the next step to strip the objects and lists of each RANDOM_STRING, leaving me with a file that shows all RANDOM_STRING names only.
How can I accomplish this using jq?
Expected Output:
RANDOM_STRING1
RANDOM_STRING2
RANDOM_STRING3
RANDOM_STRING4
.....
RANDOM_STRING100000
Apparently you're shooting for:
jq -r '.[][] | keys_unsorted[]'
or perhaps:
jq -c '[.[][] | keys_unsorted[]]'