Skip to content

Instantly share code, notes, and snippets.

@AmrEldib
Created October 12, 2014 22:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmrEldib/eba75332bac8570969c7 to your computer and use it in GitHub Desktop.
Save AmrEldib/eba75332bac8570969c7 to your computer and use it in GitHub Desktop.
Split JSON Array to Multiple Files
// 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) ); } );
@josephnaber
Copy link

const fs = require('fs');

const itemsArray = require('./metadata.json');

itemsArray.forEach( function (item, index) { fs.writeFileSync('ipfs-folder/' + index + '.json', JSON.stringify(item) ); } );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment