JSON Module #28 Flashcards

1
Q

What types of data does JSON support?

A

Number: any number that’s not wrapped in quotes

String: any set of characters wrapped in quotes

Boolean: true or false
Array: a list of values, wrapped in square brackets

Object: a set of key-value pairs, wrapped in curly brackets

null: the null word, which represents an empty value

Any other data type that’s more complex than this must
be serialized to a string (and then de-serialized) in order to be stored in JSON.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which method will return an object that contains the parsed JSON

A

JSON.parse takes a JSON string as its parameter, and returns an object that contains the parsed JSON:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does JSON.stringify( ) do?

A

JSON.stringify() takes a JavaScript object as its parameter, and returns a string that represents it in JSON:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which second argument does JSON accept

A

The reviver function: You can use that to customize the JSON parsing and perform any custom operation:

JSON.parse(string, (key, value) => {
  if (key === "name") {
    return `The name is ${value}`
  } else {
    return value
  }
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly