I'm trying to save some values from a bash-array into an existing json. I tried some different approaches, but I didn't manage to solve the issue. What am I missing here?
input.json
{
"type": "FeatureCollection",
"name": "test",
"features": [
{ "type": "Feature", "properties": { "OBJECTID": 3213, "USE": "dem", "tile": "4045644"}},
{ "type": "Feature", "properties": { "OBJECTID": 3214, "USE": "dem", "tile": "4045646"}},
{ "type": "Feature", "properties": { "OBJECTID": 3215, "USE": "dem", "tile": "4045648"}}
]
}
Output of some calculations in Bash - 100% derived from input.json. So this array length == length of the "features[]"-array in the input.json
printf '%s\n' "${pushintojson[@]}"
4045646 NV NV NV
4045648 NV 4045644 NV
4045650 NV 4045646 NV
jq '.features |= map(.properties += {NOSW: $ARGS.positional})' --args "${pushintojson[@]}" <<< "${input.json}"
So this produces this (newlines added by me for readability):
{
"type":"FeatureCollection",
"name":"test",
"features": [
{"type":"Feature","properties":{"OBJECTID":3213,"USE":"dem","tile":"4045644",
"NOSW":[
"4045646 NV NV NV",
"4045648 NV 4045644 NV",
"4045650 NV 4045646 NV"
]}},
{"type":"Feature","properties":{"OBJECTID":3214,"USE":"dem","tile":"4045646",
"NOSW":[
"4045646 NV NV NV",
"4045648 NV 4045644 NV",
"4045650 NV 4045646 NV"
]}},
{"type":"Feature","properties":{"OBJECTID":3215,"USE":"dem","tile":"4045648",
"NOSW":[
"4045646 NV NV NV",
"4045648 NV 4045644 NV",
"4045650 NV 4045646 NV"
]}}
]
}
All values of the bash-array are saved to EVERY element. It's supposed to be just one value per json-object - actually as an array itself. So in pseudo: "pushintojson[0]" needs to be under "features[0]", pushintojson[1]" to "features[1]" pushintojson[2]" to "features[2]" etc.
DESIRED OUTPUT
{
"type":"FeatureCollection",
"name":"test",
"features": [
{"type":"Feature","properties":{"OBJECTID":3213,"USE":"dem","tile":"4045644",
"NOSW":"4045646 NV NV NV"
}},
{"type":"Feature","properties":{"OBJECTID":3214,"USE":"dem","tile":"4045646",
"NOSW":"4045648 NV 4045644 NV"
}},
{"type":"Feature","properties":{"OBJECTID":3215,"USE":"dem","tile":"4045648",
"NOSW":"4045650 NV 4045646 NV"
}}
]
}