0
"[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]"

convert to this

[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]
2
  • JSON.parse()? Commented Aug 5, 2019 at 6:14
  • I am try this code but not work Commented Aug 5, 2019 at 6:17

2 Answers 2

3

Instead of (Invalid string)

"[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]"

Use this

'[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]'

For example :

var str = '[{"question":false,"choices":["Database","Email","Command line"],"correctAnswer":1},{"question":false,"choices":["Horizon","Sunset","Nightfall"],"correctAnswer":1}]'
console.log(JSON.parse(str))

Reason: If there is double quote inside a string then you can not use a double quote to enclose that string. As there is always a double quote inside a JSON string, you can use a single quote('') or a template string (``) to enclose it.

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

Comments

0

You need to use JSON.parse() because It's already stringified.

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.