Created
October 12, 2014 22:27
-
-
Save AmrEldib/eba75332bac8570969c7 to your computer and use it in GitHub Desktop.
Split JSON Array to Multiple Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script uses Node.js | |
// the 'arrayFile.json' is in the same folder as where you're running this command. | |
// This is not a script, but just the commands. Run from the shell. | |
// Sample item from the JSON file: | |
// { "id": "1" , "name": "one" } | |
// Files are saved under the folder 'itemsFolder', each item is saved in a JSON file name '<id>.json'. | |
var itemsArray = require('./arrayFile.json'); | |
itemsArray.forEach( function (item) { item.writeFileSync('itemsFolder/' + item.id + '.json', JSON.stringify(item) ); } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
const fs = require('fs');
const itemsArray = require('./metadata.json');
itemsArray.forEach( function (item, index) { fs.writeFileSync('ipfs-folder/' + index + '.json', JSON.stringify(item) ); } );