Created
September 1, 2012 06:08
-
-
Save tlync/3565248 to your computer and use it in GitHub Desktop.
Split large json file
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
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++ | |
} | |
}) |
node split-json.js .json
Love it!
I was not aware of this, thanks for sharing!
11 years later... Thanks 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use this ?