- Published on
How works JSON.parse()
en | ptBR
JSON is defined recursively (recursive function calls itself until it finds something that stops). All
Array (with valid JSONs), objects whose keys are strings and whose values are valid JSONs and
Null are valid JSONs.
String, causing its contents to be read correctly by the computer.
For this reason, the syntax for transforming the String
"2" into Number, is
O que é JSON.parse()
JSON.parse() gets the string representation of a valid JSON.
console.log(typeof JSON.parse('true')) // booleanconsole.log(typeof JSON.parse('false')) // booleanconsole.log(typeof JSON.parse('20')) // numberconsole.log(Boolean('false')) // true
JSON.parse() can transform the
If JSON.parse("false") is false, why Boolean("false") is true?
false, it needs to be:
null, everything else like values, objects, array empty and a non-empty
true, regardless of what content is in it.