здесь массив SubThings заполняется
$ echo '[{"thing-1" : "meta1","thing-2" : "meta2","thing-n" : "metan","subThings":[{"subThing-1" : "subMeta1","subThing-2" : "subMeta2","subThing-n" : "subMetan"}]}]' | jq '.'
[
{
"subThings": [
{
"subThing-n": "subMetan",
"subThing-2": "subMeta2",
"subThing-1": "subMeta1"
}
],
"thing-n": "metan",
"thing-2": "meta2",
"thing-1": "meta1"
}
]
вы можете видеть здесь, что недостающие ключи просто установлены в нуль.
$ echo '[{"thing-1" : "meta1","thing-2" : "meta2","thing-n" : "metan","subThings":[{"subThing-1" : "subMeta1","subThing-2" : "subMeta2","subThing-n" : "subMetan"}]}]' |
jq '[.[] | {"thing-1","thing-5","subThing-2":.subThings[]["subThing-2"],}]'
[
{
"subThing-2": "subMeta2",
"thing-5": null,
"thing-1": "meta1"
}
]
здесь массив SubThings пуст
$ echo '[{"thing-1" : "meta1","thing-2" : "meta2","thing-n" : "metan","subThings":[]}]' | jq '.'
[
{
"subThings": [],
"thing-n": "metan",
"thing-2": "meta2",
"thing-1": "meta1"
}
]
вместо нулей для subThing-2 стирает все данные.
$ echo '[{"thing-1" : "meta1","thing-2" : "meta2","thing-n" : "metan","subThings":[]}]' |
jq '[.[] | {"thing-1","thing-5","subThing-2":.subThings[]["subThing-2"],}]'
[]
$
Почему?
Есть ли другой способ получить данные без очистки массива пустым массивом?