简体   繁体   English

如何将单线 JSON 转换为多线?

[英]How to convert single-line JSON to multi-line?

I'm copy-pasting JSON from a server log into Postman.我正在将服务器日志中的 JSON 复制粘贴到 Postman 中。 The JSON in the server log is single-line like this:服务器日志中的 JSON 是这样的单行:

{"a": 1, "b": 2}

but I want it to be multi-line like this:但我希望它是这样的多行:

{
  "a": 1,
  "b": 2
}

Is there a way to do this in Postman or elsewhere other than manually?除了手动之外,有没有办法在 Postman 或其他地方做到这一点?

Postman has a button "Beautify" in the top right corner. Postman 在右上角有一个“美化”按钮。 Click it to be happy.点击它会很开心。

You can parse the JSON, then stringify it again:您可以解析 JSON,然后再次对其进行字符串化:

 const json = `{"a": 1, "b": 2}`; const res = JSON.stringify(JSON.parse(json), 0, 2) console.log(res)

I don't know about postman but in VS Code you can format document just " right-click mouse btn in VScode > format document with > JSON Language Feature " although it works only if its fully JSON file not js.我不知道 postman 但在 VS Code 中,您只需“在 VScode 中右键单击鼠标 btn > 使用 > JSON 语言功能格式化文档”,尽管它仅在其完全 Z0ECD11C1D7A287401D14A 文件不是 js.287401D1478 时才有效

sorry I want to write it in a comment but I don't have many reputations对不起,我想在评论中写它,但我没有很多声誉

There are many JSON formatters in the web. web 中有许多 JSON 格式化程序。

I like this one: https://jsonformatter.curiousconcept.com/我喜欢这个: https://jsonformatter.curiousconcept.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM