本文介绍了使用jq合并json文件(每个文件一个输入对象->一个更大的输出对象,而不是列表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用"jq -s.file1 file2"合并两个json文件,但是我希望它们能够以逗号分隔的方式合并.另外,它不应该以[]
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 []
文件1:
{
"node1": {
"Environment": "PRD",
"OS": "linux"
},
"node2": {
"Environment": "NPR",
"OS": "linux"
}
}
文件2:
{
"node3": {
"Environment": "PRD",
"OS": "linux"
},
"node4": {
"Environment": "NPR",
"OS": "linux"
}
}
使用jq -s输出.文件1文件2
[
{
"node1": {
"Environment": "PRD",
"OS": "linux"
},
"node2": {
"Environment": "NPR",
"OS": "linux"
}
},
{
"node3": {
"Environment": "PRD",
"OS": "linux"
},
"node4": {
"Environment": "NPR",
"OS": "linux"
}
}
]
必需的输出:
{
"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!
推荐答案
一个选择可以延长尝试的时间:
One option slong the lines of your attempt:
jq -s add file1 file2
另一个:
jq -n 'input+input' file1 file2
这篇关于使用jq合并json文件(每个文件一个输入对象->一个更大的输出对象,而不是列表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!