I am getting error while validating the below JSON. Can you please explain why ? In JSON, can’t we put one curly braces inside another ?
{
"header":{
"appId":"xxyy"
,"token":"token"
,"messageId":"messageId"
}
,{
"message_timestamp":"2022-12-07 11:35::44"
,"wins2rms":{
"data_ind":"NONSELLABLE"
,"data_row":6
,"data_set":[
{
"loc":"9981"
,"loc_type":"W"
,"item":"00000160"
,"qty":20
,"reason":"Q"
,"rms_ind":"Y"
}
]
}
}
}
Error: Parse error on line 6:
...": "messageId" }, { "message_timesta
---------------------^
Expecting 'STRING', got '{'
Thanks
2
Answers
The error is caused by the fact that the JSON object you have provided is not valid. In JSON, objects are represented using curly braces ({ and }). You cannot put one set of curly braces inside another, as you have done on lines 6 and 7.
Here is how the JSON object should be formatted:
In this version of the JSON object, the nested objects are properly formatted, with each object enclosed in its own set of curly braces. You can use a JSON validation tool to verify that the object is valid.
The error is caused while validating is because of JSON syntax error. We can use nested JSON objects but, the it is used are not a valid syntax.
In the following JSON object 6th and 7th line has an syntax error. You cannot but one set of curly braces inside another with an comma.
In above object can modified as.
We can use curly braces inside another with an comma in an array of JSON object. Below is an example that showcases how it can be used.