I have a JSON structure and I only want to print the entries that are simple types, e.g. not arrays or objects.
Sample input:
{
"person": {
"address": {
"city": "NY",
"street": "Wall Street"
},
"god": true,
"nicks": [
"Lar",
"L",
"Yo"
],
"name": "Larry",
"id": 1
}
}
Expected output:
"god": true,
"name": "Larry",
"id": 1
I tried many different variations on this which did not work:
jq '.person | with_entries(.) | select(map(type) != "array" and map(type) != "object")'
Please note that I am on jq version 1.3.
Thanks in advance for any help.
You're not really doing anything with the with_entries
call there. But you probably should be filtering there. Filter the entries where the value's type is neither an array nor an object.
.person | with_entries(select(.value | type | . != "array" and . != "object"))
If you were on a more recent version of jq, you could filter using the scalars
builtin which effectively does the same thing.
.person | with_entries(select(.value | scalars))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments