How can I remove escape sequences from JSON.stringify so that it's human-readable?

前端 未结 4 2101
走了就别回头了
走了就别回头了 2020-12-10 17:10

When I call JSON.stringify() on a complex object in JavaScript, it produces a string with lots of escape sequences (\\\", \\\\\", etc.).

How can I make it create a h

4条回答
  •  爱一瞬间的悲伤
    2020-12-10 17:48

    You can use formatting on JSON.stringify.

    '\t' represent a tab character

    JSON.stringify({ uno: 1, dos: 2 }, null, '\t');
    // returns the string:
    // '{
    //     "uno": 1,
    //     "dos": 2
    // }'
    

提交回复
热议问题