0% found this document useful (0 votes)
29 views8 pages

Understanding Json 1722831556

Uploaded by

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

Understanding Json 1722831556

Uploaded by

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

sosamson.

com
JAVASCRIPT

JSON
OBJECT NOTATION
sosamson.com

JSON
JSON stands for JavaScript Object Notation.
JSON is a lightweight format for storing & transporting
data.
JSON is "self-describing" and easy to understand.
JSON is often used when data is sent from a server to a
web page.

[{”cit
Client y”:”pa
ris”,
“unit
s”:”c”
}] Server
JSON
Request /service/weather
Response
HTTP POST (REST Interface)
[{”low”:”16”, “high”:”23”}]
JSON EXAMPLE
{
“employees”:[
{”firstName” : ”John”, “lastName” : ”Doe”},
{”firstName” : ”Anna”, “lastName” : ”Smith”},
{”firstName” : ”Peter”, “lastName” : ”Jones”}
]
}

This example defines an employees object: an array of


3 employee records (objects)

sosamson.com Key and Values


KEY AND VALUES
The two primary parts that make up JSON are keys and
values.
Together they make a key/value pair :-
Key: A key is always a string enclosed in quotation marks.
Value: A value can be a string, number, boolean
expression, array, or object.

Key “name” : “aditya” Value

The key is "name" and the value is "aditya".

sosamson.com JSON.parse()
JSON.parse()
When receiving data from a web server, the data is
always a string.

Imagine we received this text from a web server

'{ "name": "Aditya", "age": 19, "country": "India"}'

Use the JavaScript function JSON.parse() to convert


text into a JavaScript object

var obj = JSON.parse('{"name";"Aditya", *age":19, "country";"India"}');

sosamson.com JSON.stringify()
JSON.stringify()
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.

SYNTAX

JSON. stringify(value, replacer, space)

JSON String
JavaScript Object
JSON.parse()
‘{
{
“language”:“JavaScript”,
language:‘JavaScript’,
“IDE”:“Visual Studio”, JSON.stringify()
IDE:‘Visual Studio’,
“Theme”:“dark”
Theme:‘dark’
}’
}

sosamson.com
JSON VALUES
in JSON, values must be one of the following data types:

string
number
object (JSON object)
array
boolean
null

JSON

sosamson.com Let’s Summarize


RECAP

JSON is a minimal data format. Just by learning a


few key principles you can decode an entire site's
worth of JSON.

JSON

sosamson.com

You might also like