问题
I am merging two json files using "jq -s . file1 file2", but I want them to get merged without comma separation. Also it shouldn't start with []
file 1:
{
"node1": {
"Environment": "PRD",
"OS": "linux"
},
"node2": {
"Environment": "NPR",
"OS": "linux"
}
}
file 2:
{
"node3": {
"Environment": "PRD",
"OS": "linux"
},
"node4": {
"Environment": "NPR",
"OS": "linux"
}
}
Output using jq -s . file 1 file 2
[
{
"node1": {
"Environment": "PRD",
"OS": "linux"
},
"node2": {
"Environment": "NPR",
"OS": "linux"
}
},
{
"node3": {
"Environment": "PRD",
"OS": "linux"
},
"node4": {
"Environment": "NPR",
"OS": "linux"
}
}
]
Required output:
{
"node1": {
"Environment": "PRD",
"OS": "linux"
},
"node2": {
"Environment": "NPR",
"OS": "linux"
},
"node3": {
"Environment": "PRD",
"OS": "linux"
},
"node4": {
"Environment": "NPR",
"OS": "linux"
}
}
Can anyone help me finding solution to this, Thank you!
回答1:
One option slong the lines of your attempt:
jq -s add file1 file2
Another:
jq -n 'input+input' file1 file2
来源:https://stackoverflow.com/questions/61769820/merge-json-files-using-jq-one-input-object-per-file-one-larger-output-object