How to separate different objects appearing on the same line?

Viewed 83

So I created an array of objects that contain some data like name, id, etc.... I used the res.json() method to transform the array of objects into json data so that my browser would be able to use it. The problem is that I typed the array of object data like this:

[
  {

    id: 1,
    name: 'albany sofa', 
    image:   'https://dl.airtable.com/.attachments/6ac7f7b55d505
    price: 39.95,
    desc: `I'm baby direct trade farm-to-table hell of, YOLO readymade raw denim venmo whatever organic gluten-free kitsch schlitz irony af flexitarian.`,
  }, 

  {

    id: 2,
    name: 'entertainment center',
    image:'https://dl.airtable.com/.attachments/
    price: 29.98,
    desc: `I'm baby direct trade farm-to-table hell of, YOLO readymade raw denim venmo whatever organic gluten-free kitsch schlitz irony af flexitarian.`,
  },
]

Whenever I launch my server, the data comes out like this:

`[{"id":1,"name":"albanysofa","image":"https://dl.airtable.com/.attachments/6ac7f7b55d505057317534722e5a9f03/9183491e/product-3.jpg","price":39.95,"desc":"I'm baby direct trade farm-to-table hell of, YOLO readymade raw denim venmo whatever organic gluten-free kitsch schlitz irony af flexitarian."},{"id":2,"name":"entertainmentcenter","image":"https://dl.airtable.com/.attachments/da5e17fd71f50578d525dd5f596e407e/d5e88ac8/product-2.jpg","price":29.98,"desc":"I'm baby direct trade farm-to-table hell of, YOLO readymade raw denim venmo whatever organic gluten-free kitsch schlitz irony af flexitarian."}`

Meaning that it appears on one line. Meanwhile when I typed it out, I organized it. How do I fix it? Is this not as big an issue as I am seeing it? Also, when I checked for the content-type in the browser, it was missing.

1 Answers

Addidional spaces and new lines are ignored inside JSON. So the JSON data you have posted is perfectly valid and will be parsed normal by any fuction that requires a JSON parameter. Many API testing tools support JSON beautify ex. in Postman by default, JSON is represented "Pretty".

enter image description here

If for readability or other reasons you'd want to view your JSON like that, you can use 3rd party JSON beautifier tools.

Related