Skip to content

Commit 7b486a1

Browse files
authored
Update JSON.md
1 parent 6c686f8 commit 7b486a1

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

JSON.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11
# JSON
22

3+
> MDN documentation: JSON is a syntax for serializing objects, arrays, numbers, strings, booleans, and null. It is based upon JavaScript syntax but is distinct from it: some JavaScript is not JSON.
4+
5+
## Object
6+
7+
```json
8+
{
9+
"firstName": "Alex",
10+
"lastName": "Paul"
11+
}
12+
```
13+
14+
## Array
15+
16+
```json
17+
[
18+
{
19+
"firstName": "Alex",
20+
"lastName": "Paul"
21+
},
22+
23+
{
24+
"firstName": "John",
25+
"lastName": "Appleseed"
26+
}
27+
]
28+
```
29+
330
## Converting an Object to JSON data `JSON.stringify()`
431

32+
> MDN documentation: The `JSON.stringify()` method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
33+
534
```javascript
635
const book = new Object({
736
title: "1984",
@@ -40,6 +69,8 @@ console.log(booksJSON);
4069

4170
## Converting JSON to JavaScript `JSON.parse()`
4271

72+
> MDN documentation: The `JSON.parse()` method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
73+
4374
```javascript
4475
let data = bookJSON;
4576
let parsed = JSON.parse(data);
@@ -56,3 +87,7 @@ console.log(`There are ${parsedBooks.length} books in the collection.`)
5687
console.log(`The author of the second book is ${parsedBooks[1].author}`)
5788
// The author of the second book is Michelle Obama
5889
```
90+
91+
## Resources
92+
93+
1. [MDN - JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)

0 commit comments

Comments
 (0)