Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76324dd

Browse files
chapter 1.11 and 1.12 uploaded
chapter 1.11 and 1.12 uploaded
1 parent c2d508c commit 76324dd

File tree

1 file changed

+106
-3
lines changed

1 file changed

+106
-3
lines changed

‎readme.md

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ Topics included/covered
7979
- 1.8. [JSON vs XML Trends](#18-json-vs-xml-trends)
8080
- 1.9. [JSON Data Types](#19-json-data-types)
8181
- 1.10. [Access-Modify JSON object data](#110-access-modify-json-object-data)
82+
- 1.11. [JSON Parse](#111-json-parse)
83+
- 1.12. [JSON Stringify](#112-json-stringify)
84+
8285

8386
<!--
8487
2. [JSON Resources](#2-json-resources)
@@ -188,7 +191,7 @@ JSON represents data in the `pair of curly braces and in the form of key-value p
188191
189192
```
190193

191-
To access or read data from a JSON object, we simply need to use property name with `. dot notation`, will get all IntelliSense as soon as will use any jsonObjectName.propertyName i.e. JsonObjectName.propertyName or so.
194+
To access or read data from a JSON object, we simply need to use property name with `. dot notation`, will get all IntelliSense as soon as will use any `jsonObjectName.propertyName` i.e. `JsonObjectName.propertyName` or so.
192195

193196
As soon as we assign JSON format/values to any JavaScript variable, it becomes a JavaScript object to which we can access via `. dot notation`.
194197

@@ -379,12 +382,12 @@ To access, read or modify JSON object data, we simply need to use property name
379382

380383
As soon as we assign JSON format/values to any JavaScript variable, it becomes a JavaScript object to which we can access via `. dot notation`.
381384

382-
```jsonObjectName.propertyName``` or ```TechnologyJSON.technologyName```
385+
> **Syntax**: ```jsonObjectName.propertyName``` or ```TechnologyJSON.technologyName```
383386
384387
### 1.10.2. Square bracket
385388
Second or another way to access, read or modify JSON object data is Square bracket notation
386389

387-
```jsonObjectName.['propertyName']``` or ```TechnologyJSON.['technologyName']```
390+
> **Syntax**: ```jsonObjectName.['propertyName']``` or ```TechnologyJSON.['technologyName']```
388391
389392
> **Syntax & Example**: `1.10.1-access-modify-json-data.html`
390393
@@ -442,3 +445,103 @@ Second or another way to access, read or modify JSON object data is Square brack
442445
443446
</html>
444447
```
448+
449+
450+
1.11. JSON Parse
451+
---------------------
452+
453+
1.11. Converting a JSON string to JSON array/object
454+
---------------------
455+
456+
- `JSON.parse()` method converts a JSON string to JSON array/object
457+
- `JSON.parse()` Parse a string (written in JSON format) and return a JavaScript object
458+
- Usually data receiving from a web server is string, with `JSON.parse()` method one can Parse the data to JavaScript object
459+
- `JSON.parse()` was first added to the `fifth edition of ECMAScript`, which as of `2017` is supported by all major browsers
460+
461+
> **Syntax & Example**: `1.11.1-json-parse.html`
462+
463+
```
464+
<!DOCTYPE html>
465+
<html lang="en">
466+
467+
<head>
468+
<meta charset="UTF-8">
469+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
470+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
471+
<title>json-parse</title>
472+
473+
<script type="text/javascript">
474+
475+
// creating string object to hold json like data
476+
var TechnologyStringObj = '{ "technologyName": "JSON (JavaScript Object Notation)", "inventor": "Douglas Crockford", "usage": "Data storage and exchange format", "version": 1.0, "cost": 0, "license": "Open Source - MIT" }';
477+
478+
// parse a string object to json
479+
var TechnologyJSON = JSON.parse(TechnologyStringObj);
480+
console.log(TechnologyJSON);
481+
482+
// accessing data from a json object
483+
// JsonObjectName.propertyName
484+
console.log(TechnologyJSON.technologyName);
485+
486+
</script>
487+
488+
</head>
489+
490+
<body>
491+
492+
</body>
493+
494+
</html>
495+
```
496+
497+
498+
1.12. JSON Stringify
499+
---------------------
500+
501+
1.12. Converting a JSON object or JSON array into a string
502+
---------------------
503+
504+
- `JSON.stringify()` method converts a JSON object or JSON array into a string
505+
- `JSON.stringify()` method converts a JavaScript object or value to a JSON string
506+
- When sending data to a web server the data has to be a string
507+
508+
> **Syntax & Example**: `1.12.1-json-stringify.html`
509+
510+
```
511+
<!DOCTYPE html>
512+
<html lang="en">
513+
514+
<head>
515+
<meta charset="UTF-8">
516+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
517+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
518+
<title>json-stringify</title>
519+
520+
<script type="text/javascript">
521+
522+
// json object
523+
var TechnologyJSON = { "technologyName": "JSON (JavaScript Object Notation)", "inventor": "Douglas Crockford", "usage": "Data storage and exchange format", "version": 1.0, "cost": 0, "license": "Open Source - MIT" };
524+
525+
console.log(TechnologyJSON);
526+
console.log(TechnologyJSON.technologyName);
527+
528+
// parse a json object to string
529+
var TechnologyJSONStringify = JSON.stringify(TechnologyJSON);
530+
console.log(TechnologyJSONStringify);
531+
console.log(TechnologyJSONStringify.technologyName); //undefined
532+
533+
// parse a string object to json
534+
var TechnologyJSONObj = JSON.parse(TechnologyJSONStringify);
535+
console.log(TechnologyJSONObj);
536+
console.log(TechnologyJSONObj.technologyName);
537+
538+
</script>
539+
540+
</head>
541+
542+
<body>
543+
544+
</body>
545+
546+
</html>
547+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /