Skip to content
Sign upLog in
← Back to Community

JSON.parse()

Profile icon
Highwayman

Dose it work on everything or just JSON objects?

Answered by Vandesm14 [earned 5 cycles]
View Answer
Voters
Profile icon
Highwayman
Comments
hotnewtop
Profile icon
Vandesm14

JSON.parse() only works on a JSON string.

Profile icon
Highwayman

@Vandesm14

But what does that mean?

Edit: does it mean that it is
Just objects like

{ boy:'gg', 45:'khiok' }

or is it everything like

2457 or 'Hello world' or `I have ${ 45 } children` or [ 57, 'jhkk', {} ] or null or 0.89

Edit2: like if that was in a string

Profile icon
Vandesm14

@Highwayman
This is a JSON object:

{ "array": [ "Dan", "Jane", "John" ], "json": "true" }

using JSON.parse() on that string would yield this:

{ array: [ "Dan", "Jane", "John" ], json: "true" }

JSON.parse() turns any JSON object into a normal JavaScript object

Profile icon
Highwayman

@Vandesm14
so then it’s only objects. Aw. Ok ty!

Profile icon
Vandesm14

@Highwayman
Please mark my comment as the answer if I resolved your issue 👍

Profile icon
Highwayman

@Vandesm14
oops forgot sry bout that.