Single quotes are added to start and end of JSON

Single quotes are added to start and end of this JSON, after returning it to view as here.

I tried removing the first and last character with JavaScript’s substring() method to parse it with JSON.parse(), but it couldn’t be removed.

What’s the correct way to parsing it?

For those who wants the JSON;

"[{"ParameterType":"Parametre Türü1","DisplayType":"ComboBox","Parameters":[{"Name":"Parametre1","Ids":["9786057751744","9786257069335","9786057580399","0","0","0"]},{"Name":"Parametre2","Ids":["0","0","0","0","9789751969194","0"]}]},{"ParameterType":"Parametre Türü2","DisplayType":"CheckBox","Parameters":[{"Name":"Param1","Ids":["9786057751744","9786257069335","9786057580399","0","0","0"]},{"Name":"Param2","Ids":["0","0","0","0","9789751969194","0"]}]},{"ParameterType":"Parametre Türü3","DisplayType":"ComboBox","Parameters":[{"Name":"1","Ids":["9786057751744","0","0","0"]},{"Name":"2","Ids":["9786257069335","0","0","9789751969194"]},{"Name":"3","Ids":["9786057580399","0","0","0"]}]}]"

Answer

JSON encoded data does not need to be an array, object, it could also be a single string:

console.log(JSON.parse(""test""))

And that’s what you got. It is a single string. That this string by itself also contains JSON encoded data indicates that the data is encoded twice.

If you do JSON.parse(JSON.parse(data)) you will get the object. But instead of parsing the data twice, you should find the reason why it was encoded twice and fix that.

This snippet shows what happens if you encode the data twice, and it looks like the data you have shown:

let data = [{"ParameterType":"Parametre Türü1"}]

let encodedOnce = JSON.stringify(data)
let encodedTwice = JSON.stringify(encodedOnce)

console.dir(encodedTwice)

let decodedOnce = JSON.parse(encodedTwice)
let decodedTwice = JSON.parse(decodedOnce)

console.dir(decodedTwice)