json

The json statement is used to format JSON in a named buffer.

Syntax

json format_{buffername}

Details

In many cases, an API or other external source will return JSON in a densely packed format which is not easy for the human eye to read. The json statement is used to re-format JSON data that has been previously loaded into a named buffer (via the buffer statement) into a form that is friendlier to human eyes.

After the JSON has been formatted, the buffer can be saved or printed for subsequent inspection.

Example

Given the following single packed line of JSON in a named buffer called myJSON:

{
"title":"Example JSON data",
"heading":{
"category":"Documentation",
"finalised":true
},
"items":[
{
"id":"01",
"name":"Item number one",
"subvalues":{
"0":1,
"10":42,
"100":73,
"1000":100
},
"category":"Example data",
"subcategory":"First array"
},
{
"id":"02",
"name":"Item number two",
"subvalues":{

"0":10,
"10":442,
"100":783,
"1000":1009
},
"category":"Example data",
"subcategory":"First array"
}
]
}

The following USE script fragment:

json format {myJSON}
          print {myJSON}

will result in the following output:

{
"title":"Example JSON data",
"heading":{
"category":"Documentation",
"finalised":true
},
"items":[
{
"id":"01",
"name":"Item number one",
"subvalues":{
"0":1,
"10":42,
"100":73,
"1000":100
},
"category":"Example data",
"subcategory":"First array"
},
{
"id":"02",
"name":"Item number two",
"subvalues":{
"0":10,
"10":442,
"100":783,
"1000":1009
},
"category":"Example data",
"subcategory":"First array"
}
]
}

How did we do?