How can I make JavaScript recognize a string as JSON?
I have a function that only works when passed a JSON object. If I pass a string with the same format as JSON, it doesn't work. I want to find a way for the function to treat the string as JSON, even though it is already in JSON format.
I attempted using Ajax to input the string, setting the "handle as" parameter to "JSON". When passing the result of this input to the function, it works successfully.
This led me to believe that the issue is not with the string itself. How can I convert this string into JSON? It seems that receiving the same string through an Ajax request and then passing it to the function works, while passing it directly does not.
The string looks like this:
{
"data": [
{
"id": "id1",
"fields": [
{
"id": "name1",
"label": "joker",
"unit": "year"
},
{"id": "name2", "label": "Quantity"},
],
"rows": [ data here....
and closing braces..