最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to convert single-line JSON to multi-line? - Stack Overflow

programmeradmin1浏览0评论

I'm copy-pasting JSON from a server log into Postman. The JSON in the server log is single-line like this:

{"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?

I'm copy-pasting JSON from a server log into Postman. The JSON in the server log is single-line like this:

{"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?

Share Improve this question edited Dec 16, 2021 at 9:50 Mark Rotteveel 109k229 gold badges156 silver badges220 bronze badges asked Dec 14, 2021 at 3:21 gkeenleygkeenley 7,41816 gold badges77 silver badges178 bronze badges 1
  • this process is called JSON beautify and is available in almost all popular programming languages – tsamridh86 Commented Dec 14, 2021 at 3:29
Add a ment  | 

3 Answers 3

Reset to default 4

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.

sorry I want to write it in a ment but I don't have many reputations

Postman has a button "Beautify" in the top right corner. Click it to be happy.

You can parse the JSON, then stringify it again:

const json = `{"a": 1, "b": 2}`;

const res = JSON.stringify(JSON.parse(json), 0, 2)
console.log(res)

发布评论

评论列表(0)

  1. 暂无评论