How can I pretty-print JSON using node.js?

前端 未结 6 1064
心在旅途
心在旅途 2020-11-28 00:22

This seems like a solved problem but I am unable to find a solution for it.

Basically, I read a JSON file, change a key, and write back the new JSON to the same file

6条回答
  •  醉话见心
    2020-11-28 00:51

    If you don't want to store this anywhere, but just view the object for debugging purposes.

    console.log(JSON.stringify(object, null, "  "));
    

    You can change the third parameter to adjust the indentation.

提交回复
热议问题