JSON – stringify and parse

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

JSON – stringify and parse

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does JSON.stringify() convert a JS value into a JSON string?
A No
B Yes
2. Does JSON.parse() convert a JSON string into a JS value?
A No
B Yes
3. Is 'json' with a lowercase j valid for JSON.stringify()?
A No
B Yes
4. Must 'stringify' be written in lowercase?
A Yes
B No
5. Must 'parse' be written in lowercase?
A Yes
B No

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1JSON.stringify(person) AJSON.parse(text)
2JSON.parse(json) BWrong - 'parse' must be lowercase
3Converts a JS value into a JSON-formatted string CJSON.stringify(data)
4Converts a JSON string into a usable JS value DConverts a JSON string back into a JS value
5let j = json.stringify(obj); EWrong - 'JSON' must be capitalized
6let o = JSON.Parse(text); FConverts the person object into a JSON string

Definitions

JSON.stringify()

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
let json = JSON._________(person);
2.
let obj = JSON._____(json);
3.
let text = JSON._________(data);
4.
let result = JSON._____(text);
5.
let data2 = JSON._________({a: 1});

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let j = json.parse(s);
B let s = '{"a":1}';
C console.log(j);
Question 2
A let t = {b: 2};
B let j = JSON.Stringify(t);
C console.log(j);
Question 3
A let u = {c: 3};
B let j2 = JSON.stringify(u);
C let k = JSON.Parse(j2);
Question 4
A let m = Json.stringify(x);
B let x = {d: 4};
C console.log(m);
Question 5
A let y = {e: 5};
B let n = JSON.stringfy(y);
C console.log(n);

Answer Key

JSON – stringify and parse
Section A: Quick Questions
Q1
B — Yes
Q2
B — Yes
Q3
A — No
Q4
A — Yes
Q5
A — Yes
Section B: Match the Pairs
Q1
JSON.stringify(person) → Converts the person object into a JSON string
Q2
JSON.parse(json) → Converts a JSON string back into a JS value
Q3
Converts a JS value into a JSON-formatted string → JSON.stringify(data)
Q4
Converts a JSON string into a usable JS value → JSON.parse(text)
Q5
let j = json.stringify(obj); → Wrong - 'JSON' must be capitalized
Q6
let o = JSON.Parse(text); → Wrong - 'parse' must be lowercase
Section C: Definitions
Q1
JSON.stringify() — Converts a JavaScript value into a JSON-formatted string.
Section D: Fill in the Blanks
Q1
let json = JSON.stringify(person);
Q2
let obj = JSON.parse(json);
Q3
let text = JSON.stringify(data);
Q4
let result = JSON.parse(text);
Q5
let data2 = JSON.stringify({a: 1});
Section E: Spot the Error
Q1
A — 'JSON' must be capitalized - it's not 'json'.
Q2
B — 'stringify' must be lowercase - a capital S causes an error.
Q3
C — 'parse' must be lowercase - a capital P causes an error.
Q4
A — 'JSON' must be all uppercase, not 'Json'.
Q5
B — 'stringify' is misspelled as 'stringfy'.