I think this could be a possible solution:
const fs = require("fs");
let files = fs.readdirSync("library");
function mergeJson() {
const output = files.reduce((acum, current) => {
data = fs.readFileSync(`./library/${current}`);
const newData = JSON.parse(data);
return {
...acum,
...newData,
};
}, {});
if (output) {
fs.writeFileSync(`combine.json`, JSON.stringify(output), { flag: "a" });
}
}
mergeJson();
Answer from Franco Aguilera on Stack OverflowGitHub
github.com › mtacnet › json-merger
GitHub - mtacnet/json-merger: Merge multiple JSON files - Vanilla JavaScript and HTML (graphic mode: browser+explorer)
Merge multiple JSON files - Vanilla JavaScript and HTML (graphic mode: browser+explorer) - mtacnet/json-merger
Starred by 4 users
Forked by 4 users
Languages JavaScript 89.1% | HTML 10.9% | JavaScript 89.1% | HTML 10.9%
GitHub
github.com › userpixel › combine-json
GitHub - alexewerlof/combine-json: Combines a group of files into one JavaScript object
June 28, 2021 - const { combine } = require('combine-json') const myBigJsonObject = await combine('path/to/the/root/dir')
Starred by 17 users
Forked by 2 users
Languages JavaScript 100.0% | JavaScript 100.0%
Videos
09:00
How to merge two JSON files in the command-line using jq? - YouTube
Jackson API to convert Java objects into Json file formats | ...
05:23
JSON Basics JSON multiple objects within JSON files - YouTube
merge json objects using spread operator. #trending ...
01:39
How to concatenate (merge) two JSON arrays - YouTube
GitHub
github.com › boschni › json-merger
GitHub - boschni/json-merger: Merge JSON files and objects with indicators like $import $remove $replace $merge
Use $move.value to not only move the item but also merge it with a value. ... { "someArray": [ { "$match": { "query": "$[?(@.a == 3)]", "value": { "$move": { "index": 0, "value": { "b": 3 } } } } } ] } ... Use the $select operation to select one or multiple values.
Starred by 50 users
Forked by 17 users
Languages JavaScript 62.7% | TypeScript 37.3% | JavaScript 62.7% | TypeScript 37.3%
GitHub
github.com › elamaranae › merge-json
GitHub - elamaranae/merge-json: Merge multiple JSON files into JSON files of specific size. · GitHub
input - folder that contains input files output - folder that contains output files merge_json.js - script to perform merging parameters can be change inside the program as specified below, merge(INPUT_FOLDER_NAME, INPUT_FILE_BASENAME, OUTPUT_FOLDER_NAME, OUTPUT_FILE_BASENAME, MAX_FILE_LIMIT_IN_BYTES) run the code using node merge_json.js
Author elamaranae
Quora
quora.com › How-can-I-load-more-JSON-files-into-one-JSON-file-and-then-read-it-in-console-JavaScript
How to load more JSON files into one JSON file, and then read it in console (JavaScript) - Quora
This extends the first object with properties of the second. ... A simpler way to do it is to use the spread operator. ... GitHub - jhildenbiddle/mergician: Uniquely flexible and light-weight utility for cloning and deep (recursive) merging of JavaScript objects.
Medium
ekapramudita.medium.com › combining-multiple-json-files-into-a-single-json-file-8d6e608483e0
Combining Multiple JSON Files Into A Single JSON File | by Eka Aditya Pramudita | Medium
June 7, 2021 - It is better to combine a folder full of JSON files into a single JSON file. The example above shows that the process gives you more space in your memory. Also, it will ease your data processing as you will not need to iterate over files in a folder. If you’re interested in this kind of data processing, don’t hesitate to visit my GitHub page.
GitHub
gist.github.com › 3211699
Quick Node script to merge to extend one JSON file with another and save it · GitHub
December 12, 2014 - Quick Node script to merge to extend one JSON file with another and save it - extend-and-save.js
GitHub
github.com › topics › json-merger
json-merger · GitHub Topics · GitHub
August 17, 2020 - A simple CLI tool to merge multiple Swagger (OpenAPI) YAML and JSON files into a single spec. swagger swagger-generator json-merger swagger-merger go-swagger yaml-merger ... javascript json browser vanilla-javascript merge vanilla-js json-merger deepmerge explorer-filemanager json-merge
DevGenius
blog.devgenius.io › combining-json-objects-in-javascript-node-js-abe84f492d0
Combining JSON Objects in JavaScript/Node.js | by Popa Vlad | Dev Genius
March 6, 2025 - This method copies the values of ... const jsonObj2 = { city: "New York", hobby: "Coding" }; // Merge JSON objects const mergedJSON = Object.assign({}, jsonObj1, jsonObj2); console.log(mergedJSON);...
GitHub
github.com › topics › json-merge
json-merge · GitHub Topics · GitHub
June 21, 2022 - A light weight library to merge two json objects into a single json object. java json maven hacktoberfest json-merge hacktoberfest2020 ... javascript json browser vanilla-javascript merge vanilla-js json-merger deepmerge explorer-filemanager json-merge
Top answer 1 of 3
7
Can do something like this using Promise:
const fs = require('fs');
const data = {
"passed": 0,
"fixtures": []
};
const dir = `${__dirname}/data/`;
fs.readdir(dir, (err, files) => {
return new Promise((resolve, reject) => {
if (err) reject(err);
files.forEach(file => {
console.log(file);
let content = require(`${dir}${file}`);
data['passed'] += content.passed;
data['fixtures'] = data['fixtures'].concat(content['fixtures']);
});
resolve(data);
}).then(data => {
fs.writeFileSync('./final.json',JSON.stringify(data));
});
})
Using Async/Await it can done like this:
const fs = require('fs');
const path = require('path');
const dir = path.join(__dirname, 'data');
let finalContent = { "fixtures": [], "passed": 0 };
const read_directory = async dir =>
fs.readdirSync(dir).reduce((finalContent, file) => {
filePath = path.join(dir, file);
console.log(filePath);
let content = require(filePath);
finalContent.passed += content.passed;
finalContent.fixtures = finalContent.fixtures.concat(content.fixtures);
return finalContent;
}, { "passed": 0, "fixtures": [] });
read_directory(dir).then(data => {
fs.writeFileSync('./final.json', JSON.stringify(data));
});
2 of 3
0
First, deserialize the JSON into the object and put all the objects into a list and then serialize the list object to JSON.
npm
npmjs.com › package › json-merger
json-merger - npm
Merge JSON (or YAML) files and objects with operations like $import $remove $replace $merge and more.
» npm install json-merger
Published Feb 02, 2025
Version 3.0.0
Author Niek Bosch
Repository https://github.com/boschni/json-merger
Quora
quora.com › How-do-I-combine-different-JSON-files-in-JavaScript-urgent
How to combine different JSON files in JavaScript urgent - Quora
Answer (1 of 2): Can you please elaborate more or drop the question on Stack Overflow - Where Developers Learn, Share, & Build Careers.
GitHub
github.com › joshswan › gulp-merge-json
GitHub - joshswan/gulp-merge-json: A gulp plugin to merge JSON & JSON5 files into one file
January 20, 2020 - var merge = require('gulp-merge-json'); /** * Basic functionality */ gulp.src('jsonFiles/**/*.json') .pipe(merge()) .pipe(gulp.dest('./dist')); /** * Edit JSON with function */ gulp.src('jsonFiles/**/*.json') .pipe(merge({ fileName: 'file.json', edit: (parsedJson, file) => { if (parsedJson.someValue) { delete parsedJson.otherValue; } return parsedJson; }, })) .pipe(gulp.dest('./dist')); /** * Edit final JSON with transformer function */ gulp.src('jsonFiles/**/*.json') .pipe(merge({ fileName: 'file.json', transform: (mergedJson) => { return { key: { type: 'data', ...mergedJson, }; }; }, })) .pi
Starred by 36 users
Forked by 14 users
Languages JavaScript 99.6% | Shell 0.4% | JavaScript 99.6% | Shell 0.4%
GitHub
gist.github.com › abdullahceylan › 358c568653394847a55c270a62761a6d
Merge all .json file in a directory · GitHub
Merge all .json file in a directory. GitHub Gist: instantly share code, notes, and snippets.
Quora
quora.com › How-can-I-add-two-JSON-objects-into-one-object-JavaScript
How to add two JSON objects into one object JavaScript - Quora
Answer (1 of 4): The Spread syntax could be very helpful here, depending upon exactly what you want to do. [code]let obj1 = { a : ‘aValue’, b : ‘bValue’ }; let obj2 = {c : ‘cValue’, d : ‘dValue’, a : 'obj2AValue' }; let combined = { …obj1, …obj2 }; [/code]Note that if there ...
techtutorialsx
techtutorialsx.wordpress.com › 2020 › 09 › 06 › javascript-merge-json-objects
JavaScript merge JSON objects – techtutorialsx
January 25, 2025 - We will assume that we are starting from two JSON strings and, at the end, we want to obtain a single JSON string with the merged objects. Nonetheless, we will do the merging operation over the parsed objects, on their JavaScript representation.
GitHub
github.com › ipvalverde › json-merger
GitHub - ipvalverde/json-merger: Tool for merging multiple json files. · GitHub
Tool for merging multiple json files. Contribute to ipvalverde/json-merger development by creating an account on GitHub.
Author ipvalverde
Reddit
reddit.com › r/learnpython › attempting to merge multiple json files into one json file, struggling to get location of the files in my google drive. please help, code inside.
r/learnpython on Reddit: Attempting to merge multiple json files into one json file, struggling to get location of the files in my Google Drive. Please help, code inside.
December 6, 2022 -
I think my logic for getting the main task done is correct (that is merging all json files into one). Below is an example of four json files c1,...,c4. In reality I need to merge 71 json files!
files=['c1.json','c2.json','c3.json', 'c4.json'] # any tips on how to automate writing c1.json to c71.json would be hugely appreciated. Guessing I could somehow do this in a loop!!
all_json_file = os.path.join(directory_path,
"all_json_files.json")
def merge_JsonFiles(filename):
result = list()
for f1 in filename:
with open(f1, 'r') as infile:
result.extend(json.load(infile))
with open(all_json_conversations, 'w') as
output_file:
json.dump(result, output_file)
merge_JsonFiles(files)The error I'm getting says it doesn't recognise c1.json.
Any guidance here would be greatly appreciated.
Top answer 1 of 2
1
I'm confused by the reference to Google Drive. Where are the files? Are they on your filesystem, or in a remote cloud store? What is the value of directory_path?
2 of 2
1
Just use a glob: https://docs.python.org/3/library/glob.html But the issue you're having is that you're forgetting the path to the directory that contains the file: with open(f1, 'r') as infile: You can't retrieve a file simply by its filename, you have to use its path.