【发布时间】:2019-06-07 20:18:06
【问题描述】:
我在一个文件夹中有多个 JSON 文件,我想按照order.json 中给出的特定顺序将它们组合成一个文件
我已经测试了下面的代码,它合并了所有文件,但根据文件名按字母顺序排列。
jq -s . *.json > Merged.json
这是文件 Shoes.json
{ "document": { "product": "Shoes", "info": [ { "day": "1", "month": "1", "entry": "Some text about Shoes for day 1 and month 1", "code": "AJKD" }, { "day": "2", "month": "1", "entry": "Some text about Shoes for day 2 and month 1", "code": "KKGIR" } ] } }
这是文件 Watches.json
{ "document": { "product": "Watches", "info": [ { "day": "2", "month": "3", "entry": "Some text about Watches for day 2 and month 3", "code": "PEWQ" } ] } }
这是文件 Accesories.json
{ "document": { "product": "Accesories", "info": [ { "day": "7", "month": "2", "entry": "Some text about Accesories for day 7 and month 2", "code": "UYAAC" } ] } }
这是给出我想在输出中获得的顺序的文件 order.json
{
"order":{
"product 1":"Watches",
"product 2":"Accesories",
"product 3":"Shoes"
}
}
我想得到的输出文件是这样的Merged.json:
{
"document":[
{
"product":"Watches",
"info":[
{
"day":"2",
"month":"3",
"entry":"Some text about Watches for day 2 and month 3",
"code":"PEWQ"
}
]
},
{
"product":"Accesories",
"info":[
{
"day":"7",
"month":"2",
"entry":"Some text about Accesories for day 7 and month 2",
"code":"UYAAC"
}
]
},
{
"product":"Shoes",
"info":[
{
"day":"1",
"month":"1",
"entry":"Some text about Shoes for day 1 and month 1",
"code":"AJKD"
},
{
"day":"2",
"month":"1",
"entry":"Some text about Shoes for day 2 and month 1",
"code":"KKGIR"
}
]
}
]
}
也许有人可以帮我处理这个案子。
任何帮助将不胜感激。
【问题讨论】: