Update article.md
This commit is contained in:
parent
991ca66d70
commit
540ca28b3e
1 changed files with 8 additions and 8 deletions
|
@ -66,10 +66,10 @@ alert(json);
|
|||
|
||||
The method `JSON.stringify(student)` takes the object and converts it into a string.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
Please note that JSON-encoded object has several important differences from the object literal:
|
||||
Please note that a JSON-encoded object has several important differences from the object literal:
|
||||
|
||||
- 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`.
|
||||
|
@ -190,7 +190,7 @@ replacer
|
|||
space
|
||||
: Amount of space to use for formatting
|
||||
|
||||
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`.
|
||||
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`.
|
||||
|
||||
If we pass an array of properties to it, only these properties will be encoded.
|
||||
|
||||
|
@ -332,7 +332,7 @@ The `spaces` parameter is used solely for logging and nice-output purposes.
|
|||
|
||||
## Custom "toJSON"
|
||||
|
||||
Like `toString` for a string conversion, an object may provide method `toJSON` for to-JSON conversion. `JSON.stringify` automatically calls it if available.
|
||||
Like `toString` for string conversion, an object may provide method `toJSON` for to-JSON conversion. `JSON.stringify` automatically calls it if available.
|
||||
|
||||
For instance:
|
||||
|
||||
|
@ -521,7 +521,7 @@ alert( schedule.meetups[1].date.getDate() ); // works!
|
|||
## Summary
|
||||
|
||||
- JSON is a data format that has its own independent standard and libraries for most programming languages.
|
||||
- JSON supports plain objects, arrays, strings, numbers, booleans and `null`.
|
||||
- JSON supports plain objects, arrays, strings, numbers, booleans, and `null`.
|
||||
- JavaScript provides methods [JSON.stringify](mdn:js/JSON/stringify) to serialize into JSON and [JSON.parse](mdn:js/JSON/parse) to read from JSON.
|
||||
- Both methods support transformer functions for smart reading/writing.
|
||||
- If an object has `toJSON`, then it is called by `JSON.stringify`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue