Merging Two JSON Files in Linux
You can quickly merge multiple JSON files in Linux using fx with cat and --slurp.
Basic Merge
If all your JSON files contain flat objects (no nesting), you can do:
bash
cat a.json b.json | fx --slurp 'Object.assign({}, ...x)'This reads all files, combines them into one array (x), and merges them into a single object. Later values override earlier ones.
Example
a.json
json
{
"name": "Alice",
"age": 30
}b.json
json
{
"age": 35,
"city": "Berlin"
}Result
json
{
"name": "Alice",
"age": 35,
"city": "Berlin"
}Merging All JSON Files in a Directory
bash
cat *.json | fx --slurp 'Object.assign({}, ...x)'This reads all JSON files in the current directory, combines them into one array (x), and merges them into a single object. Later values override earlier ones.