-
-
Save EcomGraduates/c447402e64f904a9ccca9a600b5889e2 to your computer and use it in GitHub Desktop.
Split large json file
This file contains hidden or 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
if(process.argv.length < 3){ | |
console.log('target file path is required.') | |
process.exit(1) | |
} | |
var target = process.argv[2] | |
console.log('file: ' + target) | |
var fs = require('fs') | |
fs.readFile(target, function (err, data) { | |
if (err) throw err | |
var jsonArray = JSON.parse(data), | |
i = 1 | |
while(jsonArray.length !== 0){ | |
var fileName = target + '.' + i | |
fs.writeFileSync(fileName, JSON.stringify(jsonArray.splice(0, 500))) | |
console.log(fileName) | |
i++ | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment