JSON.parse()
converts a
JSON string back into an object.
This is also called parsing a JSON string.
JSON.parse()
takes two arguments:
In the above example,
toggleBooleanValues
is passed as
the second argument to JSON.parse
.
The function transforms properties
with boolean values by performing
the NOT
operation on the value.
If the string passed as
the first argument to JSON.parse
is not a valid JSON string,
it throws an error.
In the above example,
the key firstName
is not
wrapped in double quotes
in the userInfoJSON
string.
Hence, JSON.parse
throws an error.