You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/11-json/article.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -66,10 +66,10 @@ alert(json);
66
66
67
67
The method `JSON.stringify(student)` takes the object and converts it into a string.
68
68
69
-
The resulting `json` string is a called *JSON-encoded* or *serialized* or *stringified* or *marshalled* object. We are ready to send it over the wire or put into plain data store.
69
+
The resulting `json` string is a called *JSON-encoded* or *serialized* or *stringified* or *marshalled* object. We are ready to send it over the wire or put into a plain data store.
70
70
71
71
72
-
Please note that JSON-encoded object has several important differences from the object literal:
72
+
Please note that a JSON-encoded object has several important differences from the object literal:
73
73
74
74
- Strings use double quotes. No single quotes or backticks in JSON. So `'John'` becomes `"John"`.
75
75
- Object property names are double-quoted also. That's obligatory. So `age:30` becomes `"age":30`.
@@ -190,7 +190,7 @@ replacer
190
190
space
191
191
: Amount of space to use for formatting
192
192
193
-
Most of time, `JSON.stringify` is used with first argument only. But if we need to fine-tune the replacement process, like to filter out circular references, we can use the second argument of `JSON.stringify`.
193
+
Most of the time, `JSON.stringify` is used with the first argument only. But if we need to fine-tune the replacement process, like to filter out circular references, we can use the second argument of `JSON.stringify`.
194
194
195
195
If we pass an array of properties to it, only these properties will be encoded.
196
196
@@ -244,7 +244,7 @@ Now everything except `occupiedBy` is serialized. But the list of properties is
244
244
245
245
Fortunately, we can use a function instead of an array as the `replacer`.
246
246
247
-
The function will be called for every `(key,value)` pair and should return the "replaced" value, which will be used instead of the original one.
247
+
The function will be called for every `(key,value)` pair and should return the "replaced" value, which will be used instead of the original one.
248
248
249
249
In our case, we can return `value` "as is" for everything except `occupiedBy`. To ignore `occupiedBy`, the code below returns `undefined`:
250
250
@@ -281,7 +281,7 @@ number: 23
281
281
282
282
Please note that `replacer` function gets every key/value pair including nested objects and array items. It is applied recursively. The value of `this` inside `replacer` is the object that contains the current property.
283
283
284
-
The first call is special. It is made using a special "wrapper object": `{"": meetup}`. In other words, the first `(key,value)` pair has an empty key, and the value is the target object as a whole. That's why the first line is `":[object Object]"` in the example above.
284
+
The first call is special. It is made using a special "wrapper object": `{"": meetup}`. In other words, the first `(key,value)` pair has an empty key, and the value is the target object as a whole. That's why the first line is `":[object Object]"` in the example above.
285
285
286
286
The idea is to provide as much power for `replacer` as possible: it has a chance to analyze and replace/skip the whole object if necessary.
287
287
@@ -332,7 +332,7 @@ The `spaces` parameter is used solely for logging and nice-output purposes.
332
332
333
333
## Custom "toJSON"
334
334
335
-
Like `toString` for a string conversion, an object may provide method `toJSON` for to-JSON conversion. `JSON.stringify` automatically calls it if available.
335
+
Like `toString` for string conversion, an object may provide method `toJSON` for to-JSON conversion. `JSON.stringify` automatically calls it if available.
336
336
337
337
For instance:
338
338
@@ -409,7 +409,7 @@ str
409
409
: JSON-string to parse.
410
410
411
411
reviver
412
-
: Optional function(key,value) that will be called for each `(key,value)` pair and can transform the value.
412
+
: Optional function(key,value) that will be called for each `(key,value)` pair and can transform the value.
0 commit comments