I have a collection of files named file1.json, file2.json, file3.json
Inside each file is a JSON object representing an API response.
{“result”: {“foo”:”bar”, “etc”: “etc”}}
As part of a bigger project, I need these merged together so I can replay them later.
The JQ library is a powertool for this type of work, deep diving into the JSON structure and extracting necessary bits and pieces.
I’m only merging though, so here’s how to take each file and merge it into an array (and output to out.json)
First up we need to brew install jq
Then we can run the command on the collected files:
jq -s ‘.’ test*.json > out.json
[{"result": {"foo":"bar", "etc": "etc"}}, {"result": {"foo":"bar", "etc": "etc"}}, etc]