0

I am getting a string object after splitting from a text. Now I am trying to convert that text to a JSON object.

Text after Splitting

{location:"Web",initial:"",firmType:"",toaxfrtype:""}

When I am trying to parse it using JSON.parse, I am getting an error,

SyntaxError: Unexpected token l.

I have some other string value as the same in the above text. It was parsing fine using JSON.parse. Only the above string is not working. Can anybody help me in this issue.

2
  • Its already a object. So what do you want to achieve using JSON.parse? Commented Aug 28, 2015 at 5:56
  • en.wikipedia.org/wiki/JSON#Example Commented Aug 28, 2015 at 6:16

2 Answers 2

3

You need quotes " so change

 {location:"Web",initial:"",firmType:"",toaxfrtype:""}

to

 {"location":"Web","initial":"","firmType":"","toaxfrtype":""}

I have attached the image where it says valid now after correction. You can online validators to validate it first.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

This is not JSON. You need to quote all Strings, including the keys.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.