Birden fazla json'u tek dosyada birleştirme
4
●121
- 11-10-2021, 18:05:29Birden fazla json dosyam var. Bunları tek dosyada birleştirmenin bir yolu var mıdır? txt olur json olur fark etmez
- 11-10-2021, 18:12:59Mantığını yazacaktım sonra gittim yazacağım mantıkta olan kodu stackoverflow'dan buldum.
const jsonConcat = require('json-concat'); const fs = require('fs'); // an array of filenames to concat const files = []; const theDirectory = __dirname; // or whatever directory you want to read fs.readdirSync(theDirectory).forEach((file) => { // you may want to filter these by extension, etc. to make sure they are JSON files files.push(file); }) // pass the "files" to json concat jsonConcat({ src: files, dest: "./result.json" }, function (json) { console.log(json); }); - 11-10-2021, 19:14:14Eğer bir json'a yazdırmak yerine sadece array da birleştirecekseniz
var json1 = [COLOR=#D9DAE9][FONT=Open Sans]require("./x.json")[/FONT][/COLOR] var json2 = [COLOR=#D9DAE9][FONT=Open Sans]require("./x.json")[/FONT][/COLOR] var json3 = require("./x.json") var json = [...json1, ...json2, ...json3] console.log(json)gibi bir kullanım izleyebilirsiniz.