Created
February 19, 2017 21:44
-
-
Save jesperronn/206dda2539e31debcbd18cf0807c9c0b to your computer and use it in GitHub Desktop.
reformat json: read filename and write it again in the same name
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
#!/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