-5

I have the following string

"[
  {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  },
   {
    "userId": 1,
    "id": 5,
    "title": "laboriosam mollitia et enim quasi adipisci quia provident illum",
    "completed": false
  }
]"

How can i convert this string into a JSON?

tecnocrata
  • 901
  • 1
  • 8
  • 19

2 Answers2

1

You would need to use JSON.parse()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

JSON.parse(str)
Muhammad Usman
  • 458
  • 3
  • 9
1

Use JSON.parse() and replace the starting and ending " with backticks

JSON.parse(`[
  {
    "userId": 1,
    "id": 1,
    "title": "delectus aut autem",
    "completed": false
  },
   {
    "userId": 1,
    "id": 5,
    "title": "laboriosam mollitia et enim quasi adipisci quia provident illum",
    "completed": false
  }
]`)
mjarraya
  • 1,116
  • 1
  • 11
  • 18