Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luizstacio/json-format
JSON format for good presentation.
https://github.com/luizstacio/json-format
Last synced: 2 months ago
JSON representation
JSON format for good presentation.
- Host: GitHub
- URL: https://github.com/luizstacio/json-format
- Owner: luizstacio
- Created: 2014-07-14T03:19:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-07-19T02:11:51.000Z (over 7 years ago)
- Last Synced: 2024-10-06T13:15:57.279Z (3 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 25
- Watchers: 2
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - json-format - Parse JavaScript Object to a JSON String indented. (Packages / Formatter)
README
json-format
==========[![Build Status](https://travis-ci.org/luizstacio/json-format.svg?branch=master)](https://travis-ci.org/luizstacio/json-format.svg?branch=master)
Parse JavaScript Object to a JSON String indented.
#### Instaling
```
npm install json-format
```#### Usage
``` js
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');
});
```##### Result `example_tabs.json`
``` json
{
"a": 1,
"b": 2
}
```##### Result `example_spaces.json`
``` json
{
"a": 1,
"b": 2
}
```#### Default sizes
``` json
{
"tab": { "size": 1 },
"space": { "size": 4 }
}
```#### Config default
``` json
{
"type": "tab"
}
```[Based in this project](https://github.com/phoboslab/json-format).