Parse JavaScript Object to a JSON String indented.
npm install json-format
var jsonFormat = require('./');
var fs = require('fs');
var obj = {
a: 1,
b: 2
}
/* using config default, indent with tabs */
fs.writeFile('example_tabs.json', jsonFormat(obj), function(err){
if (err) throw err;
console.log('saved');
});
/* using indent with spaces */
var config = {
type: 'space',
size: 2
}
fs.writeFile('example_spaces.json', jsonFormat(obj, config), function(err){
if (err) throw err;
console.log('saved');
});
{
"a": 1,
"b": 2
}
{
"a": 1,
"b": 2
}
{
"tab": { "size": 1 },
"space": { "size": 4 }
}
{
"type": "tab"
}