I want to add an array with elements and value into an existing json file using jq.
I already have a file (input.json) with
{
"id": 9,
"version": 0,
"lastUpdTs": 1532371267968,
"name": "Training"
}
I want to add this into another groups array into this json (orig.json)
[
{
"name": "JAYS",
"sourceConnection": {
"name": "ORACLE_connection",
"connectionType": "JDBC",
"commProtocol": "JDBC"
},
"checked": true,
"newlyAdded": false,
"id": null,
"groups": [],
"displayName": "SCOTT",
"defaultLevel": "MANAGED"
}
]
The end result should look like
[
{
"name": "JAYS",
"sourceConnection": {
"name": "ORACLE_connection",
"connectionType": "JDBC",
"commProtocol": "JDBC"
},
"checked": true,
"newlyAdded": false,
"id": null,
"groups": [
{
"id": 9,
"version": 0,
"lastUpdTs": 1532371267968,
"name": "Training"
}
],
"displayName": "SCOTT",
"defaultLevel": "MANAGED"
}
]
I know how to add elements into an array, but not sure how to pass in from a file.
jq '.[].groups += [{"INPUT": "HERE"}]' ./orig.json