I have this data:
[{\"id\":\"42\",\"firstname\":\"Sarah\",\"lastname\":\"Dilby\",\"age\":\"40\",\"cars\":\"Yaris\"},
{\"firstname\":\"Jason\",\"lastname\":\"
I think the most appropriate solution is to format the numbers I have on my JSON objects correctly, ie not to wrap them in quotes. So:
[{"id":"42","firstname":"Sarah","lastname":"Dilby","age":"40","cars":"Yaris"},
{"firstname":"Jason","lastname":"Diry","age":"5","id":"5"},
{"id":"6","firstname":"Bilson","lastname":"Berby","age":"1","cars":"Tipo"}]
becomes:
[{"id":42,"firstname":"Sarah","lastname":"Dilby","age":40,"cars":"Yaris"},
{"firstname":"Jason","lastname":"Diry","age":5,"id":5},
{"id":6,"firstname":"Bilson","lastname":"Berby","age":1,"cars":"Tipo"}]
I'm guessing SergL's solution is good if it's not possible to correct the format of the JSON data.
To add to this, the issue in my specific case is to do with PHP's json_encode function on the server side. By default, it treats numbers as strings. To fix I had to add the JSON_NUMERIC_CHECK option to the encode method in the PHP script:
json_encode($assoc_array,JSON_NUMERIC_CHECK);