0

When I run

JSON.parse(`{name: 'test'}`);

I get an error. I'm just trying to parse a string and return it as JSON.

3
  • 3
    It should be a valid JSON {"name": "test"}. Notice the double quotes in key and value Commented Aug 3, 2020 at 20:36
  • 3
    That string is not valid JSON. Commented Aug 3, 2020 at 20:36
  • Closely related: simple JSON Parse error, not sure what went wrong. Commented Aug 3, 2020 at 21:09

1 Answer 1

5

That isn't valid JSON. Properties are named with double quotes and strings are in double quotes.

console.log(JSON.parse(`{"name": "test"}`));

You can read about JSON here: https://www.json.org/json-en.html

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

3 Comments

Ok. Thanks. So all JSON properties and names need double qoutes.
@Lukas not all values do. strings do.
@DanielA.White All property names are strings though

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.