Reputation:
I have an object which has an array of objects. I am willing to append two properties of each object inside the array and create a new key out of that. I am new to JQ and have tried various ways to do this, but not able to figure out. Need help.
Input:
{
"name": "Toyota",
"Model": "Innova",
"Details": [
{
"entry_day": "23",
"entry_month": "May"
},
{
"entry_day": "01",
"entry_month": "Jan"
}
]
}
Output I expect:
{
"name": "Toyota",
"Model": "Innova",
"Details": [
{
"entry_date": "23 May"
},
{
"entry_date": "01 Jan"
}
]
}
Upvotes: 1
Views: 2801
Reputation: 158190
You need to use the update assignment operator |=
:
jq '(.Details[]|={entry_date:"\(.entry_day) \(.entry_month)"})' input.json
Upvotes: 5