Response body in Postman is not in human-readable way, with proper indentation and line breaks

69 Views Asked by At

my response body (Pretty, JSON format) in Postman is not in human-readable way, with proper indentation and line breaks, it is such as text area. All the dates is in one line as a text. Please how can beautify the response body? Thanks.

enter image description here enter image description here

1

There are 1 best solutions below

0
Bench Vue On

Can you try this mock-server test?

Mocking Server

save as server.js

const express = require("express")
const cors = require("cors")

const app = express()
app.use(cors())

app.get("/api/data", async (req, res) => {
    data = {"rober":"15","timpe":7,"isFirstHalf":false,"place":"Ž","substitude":"K","lastChangeInfo":"A","approver":"B","createdAt":"2024-03-26","balInfo":null,"isSystRec":false,"canBeDenied":true,"from":"2024-04-22T15:30:06","to":"2024-04-22T15:40:06","periodDescription":"20. 04. 2024","note":"S"}
    res.json(data)
})

app.get("/api/long-data", async (req, res) => {
    data = {"attributes": [{"name": "username", "displayName": "${username}", "validations": {"length": {"min": 3, "max": 255}, "username-prohibited-characters": {}, "up-username-not-idn-homograph": {}}, "permissions": {"view": ["admin", "user"], "edit": ["admin", "user"]}, "multivalued": false}, {"name": "email", "displayName": "${email}", "validations": {"email": {}, "length": {"max": 255}}, "required": {"roles": ["user"]}, "permissions": {"view": ["admin", "user"], "edit": ["admin", "user"]}, "multivalued": false}, {"name": "firstName", "displayName": "${firstName}", "validations": {"length": {"max": 255}, "person-name-prohibited-characters": {}}, "required": {"roles": ["user"]}, "permissions": {"view": ["admin", "user"], "edit": ["admin", "user"]}, "multivalued": false}, {"name": "lastName", "displayName": "${lastName}", "validations": {"length": {"max": 255}, "person-name-prohibited-characters": {}}, "required": {"roles": ["user"]}, "permissions": {"view": ["admin", "user"], "edit": ["admin", "user"]}, "multivalued": false}, {"name": "custom", "displayName": "${custom}", "validations": {"length": {"max": 255}}, "annotations": {}, "permissions": {"view": ["admin"], "edit": ["admin", "user"]}, "multivalued": false}], "groups": [{"name": "user-metadata", "displayHeader": "User metadata", "displayDescription": "Attributes, which refer to user metadata"}]}
    res.json(data)
})

const port = 3000
app.listen(port, () => { console.log(`Listening on : ${port}`) })

Install node.js

if not yet install node.js in your PC.

https://nodejs.org/en/download

Install dependencies

npm install express cors

Run it

node server.js

enter image description here

Call it by Postman

GET http://localhost:3000/api/data

enter image description here

long JSON data

GET http://localhost:3000/api/long-data

enter image description here

call by cURL

Not pretty option

curl --request GET \
  --silent \
  --url 'http://localhost:3000/api/data' \
  --header 'Content-Type: application/json; charset=utf-8'

enter image description here

Pretty option Install json first

npm install -g json
curl --request GET \
  --silent \
  --url 'http://localhost:3000/api/data' \
  --header 'Content-Type: application/json; charset=utf-8' | json

enter image description here

So can you try this cURL for your real API?