I have several (~300,000) files of individual JSON objects that I want to combine into a single file that is a JSON array. How can I do this on linux assuming they are all in the location "~/data_files"?
FileA
{
name: "Test",
age: 23
}
FileB
{
name: "Foo",
age: 5
}
FileC
{
name: "Bar",
age: 5
}
Example Output: (begins and ends with brackets, and added commas between objects)
[
{
name: "Test",
age: 23
},
{
name: "Foo",
age: 5
},
{
name: "Bar",
age: 5
}
]
What I've tried:
I know I can use cat
to combine a bunch of files, not sure how to do it for all files in a directory yet, but trying to figure that out. Also trying to figure out how to have the ,
between files I'm concatenating, haven't seen a command for it yet.