MJS: JSON Methods, toJSON

MJS: JSON Methods, toJSON

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What is the full syntax of JSON.stringify?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (22)

Section 1

(22 cards)

What is the full syntax of JSON.stringify?

Front

let json = JSON.stringify(value[, replacer, space])

Back

For JSON.parse, what is reviver?

Front

Optional function(key,value) that will be called for each (key,value) pair and can transform the value.

Back

How does JSON.parse return values?

Front

As strings

Back

How do you add a custom toJSON method for your object?

Front

toJSON() { return this.number; }

Back

What are natively supported JSON types?

Front

Objects { ... } Arrays [ ... ] Primitives: strings, numbers, boolean values true/false, null.

Back

What is a limitation on nested objects in JSONification?

Front

There can be no circular references in nested objects

Back

Where is the spaces parameter located? What does it do? What is it useful for?

Front

It is the 3rd argument in JSON.stringify(), and it is optional. It tells how many spaces to add after each newline. spaces is particularly useful for logging and pretty output.

Back

What JS-specific properties are skipped by stringify?

Front

Function properties (methods). Symbolic properties. Properties that store undefined.

Back

Does the property name have to be in quotes?

Front

Yes

Back

Are nested objects supported for JSONification?

Front

Yes, and converted automatically

Back

What does the arg `replacer` in JSON.stringify do?

Front

Array of properties to encode or a mapping function function(key, value).

Back

Can we use backticks in JSON?

Front

no

Back

How do you convert a serialized date (by JSON.parse) into an actual date?

Front

Use the reviver argument to map a new Date function for every date value.

Back

What is JSON?

Front

The JSON (JavaScript Object Notation) is a general format to represent values and objects. It is described as in RFC 4627 standard. Initially it was made for JavaScript, but many other languages have libraries to handle it as well. So it's easy to use JSON for data exchange when the client uses JavaScript and the server is written on Ruby/PHP/Java/Whatever.

Back

What does JSON.stringify do?

Front

convert objects into JSON.

Back

What is the syntax of JSON.parse()?

Front

let value = JSON.parse(str[, reviver]);

Back

What does JSON.parse do?

Front

convert JSON back into an object.

Back

How do you decode a JSON-string?

Front

JSON.parse

Back

Is "new" allowed in JSON?

Front

no

Back

What are the arguments of JSON.stringify?

Front

value[, replacer, space]

Back

What are important things to know about stringify?

Front

Strings use double quotes. No single quotes or backticks in JSON. So 'John' becomes "John". Object property names are double-quoted also. That's obligatory. So age:30 becomes "age":30.

Back

Does JSON support comments?

Front

No, adding a comment to a JSON-string will invalidate it

Back