cancel
Showing results for 
Search instead for 
Did you mean: 

Converting a string to JSON doesn't work

jfpelletier
Contributor

Hello all,

I'm trying to convert a string to a JSON structure, but I'm not succeeding because the format is wrong. The JSON.parse() method says that it's not valid format for a JSON.

Here is the string:

"{language=Tamil, taskId=123},{language=French (Europe), taskId=124},{language=Russian, taskId=125}"

I was hoping that the missing double quotes and that the "=" instead of ":" would be interpreted and fixed, but I'm getting an error:

failure:
"Unable to parse JSON value"
value:
"Please check the format of the JSON value"
reason:
"Please check the format of the JSON value"

I could do some regex to add the missing double quotes and replace the "=" by ":", but is there an easier way or a way that's best recommended?

Thanks in advance to anyone who can help! 🙂

JF

1 ACCEPTED SOLUTION

ptaylor
Employee
Employee

That's the only way since your string is definitely not valid JSON. You need it to look like this:

{"language": "Tamil", "taskId": 123}

View solution in original post

5 REPLIES 5

Great! Good that you have control over the source of the string.