简体   繁体   中英

How to make JSON look pretty?

So I am trying to create an api and here is my code snippet

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:

[
   {
      "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(jsonData, null, 2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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