Formatted JSON Output

Deepak Negi
Feb 16, 2023

--

Did you know that you can see the JSON in a proper format using JSON.stringify(object,null,’\t’)

For Example: following code will print the JSON in a formatted manner

var top5Cars = {
"Top 5 Cars": [
{
"Make": "Toyota",
"Model": "Corolla",
"Year": "2022"
},
{
"Make": "Honda",
"Model": "Civic",
"Year": "2022"
},
{
"Make": "Tesla",
"Model": "Model 3",
"Year": "2022"
},
{
"Make": "Ford",
"Model": "Mustang",
"Year": "2022"
},
{
"Make": "Chevrolet",
"Model": "Silverado",
"Year": "2022"
}
]
}
gs.info(JSON.stringify(top5Cars,null,'\t'))

Result:

--

--

Deepak Negi
Deepak Negi

Written by Deepak Negi

Meet Deepak,the tech wizard and adventure enthusiast. When he's not coding on SN,you can find him exploring the mountains or searching for places with good food

No responses yet