I have this json.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
4.991669,
52.324436,
0
]
]
]
]
},
"properties": {
"neighbourhood": "Bijlmer-Oost",
"neighbourhood_group": null
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
5.079162,
52.388654,
0
]
]
]
]
},
"properties": {
"neighbourhood": null,
"neighbourhood_group": null
}
}
]
}
What I want is to add to the properties part a new key-value pair.
Someone could help me to figure it out what is the best way to do this?
I tried with this:
jq --arg dd "$d" '.features[] |= . + {properties: download_date: $dd}' /tmp/file-$d.geojson
But this is updates the whole properites like this:
"properties": {
"download_date": "2023-03-09"
}
Expected result should look like this:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
4.991669,
52.324436,
0
]
]
]
]
},
"properties": {
"neighbourhood": "Bijlmer-Oost",
"neighbourhood_group": null,
"date_added": "2022-01-01"
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
5.079162,
52.388654,
0
]
]
]
]
},
"properties": {
"neighbourhood": null,
"neighbourhood_group": null,
"date_added": "2022-01-01"
}
}
]
}
>Solution :
You can use:
$ jq --arg dd "$d" '.features[].properties += {date_added: $dd}' file