0% found this document useful (0 votes)
5 views10 pages

Json

JSON (JavaScript Object Notation) is a lightweight, language-independent data-interchange format that is easy for humans to read and write, and for machines to parse and generate. It is based on two structures: a collection of name/value pairs and an ordered list of values, and is commonly used for data transmission in web applications. JSON strings can be stored in .json files and must adhere to specific syntax rules, including the use of double quotes for strings and property names.

Uploaded by

Arofath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views10 pages

Json

JSON (JavaScript Object Notation) is a lightweight, language-independent data-interchange format that is easy for humans to read and write, and for machines to parse and generate. It is based on two structures: a collection of name/value pairs and an ordered list of values, and is commonly used for data transmission in web applications. JSON strings can be stored in .json files and must adhere to specific syntax rules, including the use of double quotes for strings and property names.

Uploaded by

Arofath
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

JSON

JavaScript Object Notation


Contents

1. Overview

2. Exchange Data

2
1. Overview

• JSON (JavaScript Object Notation) is a lightweight data-interchange format.


It is easy for humans to read and write. It is easy for machines to parse and
generate.
• It is based on a subset of the JavaScript Programming Language Standard
ECMA-262 3rd Edition - December 1999.
• JSON is a text format that is completely language independent but uses
conventions that are familiar to programmers of the C-family of languages,
including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
• It is commonly used for transmitting data in web applications (e.g.,
sending some data from the server to the client, so it can be
displayed on a web page, or vice versa).

3
1. Overview

JSON is built on two structures:

• A collection of name/value pairs. In various languages, this is realized as


an object, record, struct, dictionary, hash table, keyed list, or associative
array.

• An ordered list of values. In most languages, this is realized as an array,


vector, list, or sequence.

These are universal data structures. Virtually all modern programming


languages support them in one form or another. It makes sense that a data
format that is interchangeable with programming languages also be based on
these structures.
4
1. Overview

A JSON string can be stored in its own file, which is basically just a text file
with an extension of .json, and a MIME type of application/json.

JSON Structure

• As described above, JSON is a string whose format very much resembles


JavaScript object literal format.

• You can include the same basic data types inside JSON as you can in a
standard JavaScript object — strings, numbers, arrays, booleans, and
other object literals. This allows you to construct a data hierarchy, like so:

5
1. Overview

Syntax {
"fullname": "Reksmey",
{ "age": 25,
"key" : value "major": "IT",
} "position": "Manager",
"specialized": [
"Web Design",
"iOS App Development",
"React Native",
"Spring Framework",
"DevOps",
"Managment & Leadership",
"Project Mentor"
],
"remark": "R & D Department",
"status": true
}

6
1. Overview

Other notes
• JSON is purely a string with a specified data format — it contains only
properties, no methods.
• JSON requires double quotes to be used around strings and property names.
Single quotes are not valid other than surrounding the entire JSON string.
• Even a single misplaced comma or colon can cause a JSON file to go wrong,
and not work.
• JSON can actually take the form of any data type that is valid for inclusion
inside JSON, not just arrays or objects. So for example, a single string or
number would be valid JSON.
• Unlike in JavaScript code in which object properties may be unquoted, in
JSON only quoted strings may be used as properties.

7
2. Exchange Data

We converted the network response directly into a JavaScript object


using response.json().

But sometimes we aren't so lucky — sometimes we receive a raw JSON string,


and we need to convert it to an object ourselves:

• parse(): Accepts a JSON string as a parameter, and returns the


corresponding JavaScript object.

• stringify(): Accepts an object as a parameter, and returns the equivalent


JSON string.

8
2. Exchange Data

• We retrieve the response as text rather than JSON, by calling the text() not
json() method of the response.

• We then use parse() to convert the text to a JavaScript object.


const superHeroesText = await response.text();

const superHeroes = JSON.parse(superHeroesText);

9
Thank you
Perfect Practice, Does Perfect Thing

10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy