Timing, Async operations, and network requests Http & http 2, websockets, AJAX, Json Flashcards
1
Q
How do we convert a string in JSON format into objects?`
A
JSON.parse();
var json = '{"result":true, "count":42}'; obj = JSON.parse(json);
console.log(obj.count); // expected output: 42
2
Q
How do we convert a object or value into a JSON string?
A
JSON.stringify()
examples console.log(JSON.stringify({ x: 5, y: 6 })); // expected output: "{"x":5,"y":6}"
console.log(JSON.stringify([new Number(3), new String('false'), new Boolean(false)])); // expected output: "[3,"false",false]"
3
Q
What is Json
A
Basically a javascript object format in string form
Stands for javascript object notation. It is a text format that makes it easy to share data between devices like client and servers.
It is language independent and is an alternative to XML.
It is extremely easy to parse the text information into a javascript object.