Skip to content

fengliner/format-json-pretty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

format-json-pretty

format object to pretty json

update: Support for defining the number of indent spaces. The default is 2

INSTALL

npm install format-json-pretty

TEST

npm run test

DEMO

var formatJson = require('format-json-pretty');

var user = {
  id: 1,
  name: 'fengliner',
  color: {
    id: 1,
    name: 'fengliner'
  },
  font: [{id: 1, name: 'fengliner'}]
};

console.log(formatJson(user));

/**
{
  "id": 1,
  "name": "fengliner",
  "color": {
    "id": 1,
    "name": "fengliner"
  },
  "font": [{
    "id": 1,
    "name": "fengliner"
  }]
}
*/

 console.log(foramtJson(user, 4));

 /**
 {
    "id": 1,
    "name": "fengliner",
    "color": {
        "id": 1,
        "name": "fengliner"
    },
    "font": [{
        "id": 1,
        "name": "fengliner"
    }]
}
*/

About

format object to json

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published