JS formats JSON strings and JSON objects

Time:2021-6-23

Formatting JSON objects

const list= {name: 'lisi',age: 14,id: 1}
JSON.stringify(list, null, "\t")

Format JSON string

let list= "{name: 'lisi',age: 14,id: 1}"
list = JSON.parse(list)
JSON.stringify(list, null, "\t")

output

{
  name: 'lisi',
  age: 14,
  id: 1
}

JS formats JSON strings and JSON objects