formato json
Analizza l'oggetto JavaScript in una stringa JSON rientrata.
Installazione
1  npm install json-format
Utilizzo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23  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');
  });
Risultatoexample_tabs.json
1
2
3
4{
    "a": 1,
    "b": 2
}
Risultatoexample_spaces.json
1
2
3
4{
  "a": 1,
  "b": 2
}
Dimensioni predefinite
1
2
3
4{
  "tab": { "size": 1 },
  "space": { "size": 4 }
}
Impostazione predefinita
1
2
3{
  "type": "tab"
}
