I am working on a project that has a lot of json documents in a large file lets call it manifest.json
The files have titles such as
a-11.json
{"id":"a-11",
"name":"XN0",
"code":"H3A8FF82820F"
"status":"live"
}
a-03.json
{"id":"a-03",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
}
a-09.json
{"id":"a-09",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
}
What I want a shell script to do is to concatenate them all in alpha order and I am also need to wrap them like this:
[
{json doc},
{json doc},
{json doc
]
with a sq bracket seperated with a , so that it looks like the code below-
The join command only connects two files so thats not going to work and I have tried a combination of cat and ls but it all goes a bit wrong. I am trying to use the Linux environment rather than the MS environment here.
manifest.json
[
{"id":"a-03",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
},
{"id":"a-09",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
},
{"id":"a-11",
"name":"XN0",
"code":"H3A8FF82820F"
"status":"live"
}
]
The command
cat a-*.json > manifest.json
Gives me the following with the a-11.json doc at the top, any help appreciated.
[
{"id":"a-11",
"name":"XN0",
"code":"H3A8FF82820F"
"status":"live"
}
{"id":"a-03",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
},
{"id":"a-09",
"name":"PF1",
"code":"FFFF82820F"
"status":"live"
},
]