JSON – stringify and parse, online
Six activities your students do on their own devices. See who's finished, and their scores.
JSON – stringify and parse in one minute
What students need to know
This is exactly what the stringify() method does. stringify() turns an object or array into a JSON-formatted string.
JavaScript requires all capitals: JSON.stringify(). JavaScript is case-sensitive, so 'stringify' must be lowercase.
Mistakes students make
- 'JSON' must be capitalized - it's not 'json'.
- 'stringify' must be lowercase - a capital S causes an error.
- 'parse' must be lowercase - a capital P causes an error.
- 'JSON' must be all uppercase, not 'Json'.
What students will learn in this module
Every question in Module 46
Quick questions
- Does JSON.stringify() convert a JS value into a JSON string?ANoBYes
- Does JSON.parse() convert a JSON string into a JS value?ANoBYes
- Is 'json' with a lowercase j valid for JSON.stringify()?ANoBYes
- Must 'stringify' be written in lowercase?AYesBNo
- Must 'parse' be written in lowercase?AYesBNo
Key terms
Students type the meaning of:
JSON.stringify()
Match the pairs
JSON.stringify(person)Match it to what it doesJSON.parse(json)Match it to what it doesConverts a JS value into a JSON-formatted stringMatch it to what it doesConverts a JSON string into a usable JS valueMatch it to what it doeslet j = json.stringify(obj);Match it to what it doeslet o = JSON.Parse(text);Match it to what it doesFill in the blanks
let json = JSON._________(person);
Hint: Type the method that converts a value into a JSON string.
let obj = JSON._____(json);
Hint: Type the method that converts a JSON string back into a value.
let text = JSON._________(data);
Hint: Type the method that converts a value into a JSON string.
let result = JSON._____(text);
Hint: Type the method that converts a JSON string back into a value.
let data2 = JSON._________({a: 1});Hint: Type the method that converts a value into a JSON string.
Spot the error
Question 1
Alet j = json.parse(s);Blet s = '{"a":1}';Cconsole.log(j);
Question 2
Alet t = {b: 2};Blet j = JSON.Stringify(t);Cconsole.log(j);
Question 3
Alet u = {c: 3};Blet j2 = JSON.stringify(u);Clet k = JSON.Parse(j2);
Question 4
Alet m = Json.stringify(x);Blet x = {d: 4};Cconsole.log(m);
Question 5
Alet y = {e: 5};Blet n = JSON.stringfy(y);Cconsole.log(n);
