Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
reformat json: read filename and write it again in the same name
#!/usr/bin/env/bash
# reformat json: read filename and write it again in the same name
#
# read JSON file and save it again reformatted
#
# usage:
# `reformat my.json`
reformat(){
node -e "
var fs = require('fs')
fs.readFile('$1', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = JSON.stringify(JSON.parse(data), null, 2);
//console.log(result);
fs.writeFile('$1', result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.