简体   繁体   English

如何让 JSON 看起来漂亮?

[英]How to make JSON look pretty?

So I am trying to create an api and here is my code snippet所以我正在尝试创建一个 api,这是我的代码片段

const express = require('express');
const bodyParser = require('body-parser');
const fs = require('fs');


const steamScrape = require('./steamScrape');

console.log()
const app = express();

app.use(bodyParser.json());

app.get('/steamScrape', (req, res) => {
    res.json(steamScrape);
});

This is a snippet of my json file:这是我的 json 文件的片段:

[
   {
      "name": "asdasdadsa",
      "discount": "-40%",
      "price": "CDN$ 0.71",
   },
   {
      "name": "asdasd",
      "discount": "-40%",
      "price": "CDN$ 20.39",
   }
]

But this is how it looks when I run the server.但这就是我运行服务器时的样子。 How do I make it look pretty?怎样让它看起来漂亮? I have tried using JSON.stringify() and that adds \\n characters everywhere我试过使用 JSON.stringify() 并在各处添加 \\n 个字符

在此处输入图片说明

试试JSON.stringify(jsonData, null, 2);

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

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