JSON Array Parse Error

169 Views Asked by At

JSON editor shows error on line 5. But is not everything okay for my JSON?

My JSON file:

{
    "status": "ok",
    "errorMessage": "",
    "result": [
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    ]
}

Thanks.

2

There are 2 best solutions below

1
Rohit Sharma On

Missing curly brackets in result array.

It should be like below:

{
    "status": "ok",
    "errorMessage": "",
    "result": [{
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    }]
}

Validated on jsonlint

0
wordbug On

"result" is an array ([]) and you are defining properties within as if it was an object ({}).

You may want to make it an object:

{
   "status":"ok",
   "errorMessage":"",
   "result":{
      "data_x":[
         {
            "date":"2018-03-09T05:17:08",
            "value":12.00
         }
      ],
      "data_y":[
         {
            "date":"2018-03-09T05:17:08",
            "value":36.50
         }
      ],
      "data_z":[
         {
            "date":"2018-03-09T05:17:08",
            "value":88.50
         }
      ]
   }
}

Or, if you want to keep the array, you can do as imEnCoded says:

{
    "status": "ok",
    "errorMessage": "",
    "result": [{
        "data_x": [{
            "date": "2018-03-09T05:17:08",
            "value": 12.00
        }],
        "data_y": [{
            "date": "2018-03-09T05:17:08",
            "value": 36.50
        }],
        "data_z": [{
            "date": "2018-03-09T05:17:08",
            "value": 88.50
        }]
    }]
}