SlideShare a Scribd company logo
JSON
bishrul haq
BSc IT , HND IT
• Extended from the javascript
• JSON is a language-independent data format
• Media type is application/json
• extension is .json
2BH | JSON
3
1. Always starts and ends with curly brackets { } name and value is
separated by a colon : more than one pair is separated by comma.
2. It is the most common data format used for asynchronous
browser/server communication, largely replacing XML which is
used by AJAX.
3. For arrays put the arrays between [ ].
4. For elements put the values directly separated by commas.
BH | JSON
key/name value pairs
• { "name" : "value" }
4
Objects are comma separated
• { "name1" : "value" , "name2" : "value", "name3" : "value"}
Arrays have square brackets with values separated by comma
• { "name" : [ { "name" : "value" }, { "name" : "value" }] }
BH | JSON
In computer science, a data structure is a data organization, management, and storage format that
enables efficient access and modification.
More precisely, a data structure is a collection of data values, the relationships among them, and the
functions or operations that can be applied to the data.
5
• Collection of name/value pairs : Think Object format
• Ordered list of values : Think Array format
BH | JSON
Number - double- precision floating-point can be digits, positive or
negative, decimal fractions, exponents.
• {"name": 10}
6
String - double-quoted Unicode with backslash escaping
• {"name": "Hello world"}
Boolean - true or false
• {"name": true}
Array - ordered sequence of values uses square brackets. Values are each
separated by a comma. Indexing starts with 0.
• {"name": [{"name1": 1}, "hello", "world"]}
BH | JSON
7
Object - unordered collection with key:value pairs. Wrapped with curly
brackets {}. Colons to separate key and name. Keys should be strings and have
unique names.
• {"name": {"name1": 1,"name2": 1}}
Null - just empty
• {"name": null}
BH | JSON
8
JSON is an object which can be used to describe something. Two items with one
value described.
• { "car1": "black", "car2": "blue" }
JSON vs XML
JSON and XML are human readable
formats JSON is faster to write.
XML has not arrays. JSON much easier
to parse in JavaScript
BH | JSON
var detail = {
“firstname“ : “Bishrul",
“lastname" : “Haq",
“age“ : 24 };
Console.log ( detail );
Open up your ide.
Create an object
Output the Object (Try in using
your browser).
3
2
1
BH | JSON 9
10
Another good advantage of JSON is the ability to pass the value
or data into a JavaScript object.
var o = { foo: "bar" };
{ "foo": "bar" }
• JSON has double quotes while JavaScript can use single or doubles.
• JavaScript can include functions which is not available in JSON.
BH | JSON
11
Here are some examples for objects in JavaScript:
var haq= {};
haq.car1 = "black"
console.log(haq)
haq.car2 = "blue“
console.log(haq)
BH | JSON
var haq = {};
haq["car1"] = "black“
console.log(haq)
haq["car2"] = "blue“
console.log(haq)
var haq = {"car1" : "black" ,"car2" : "blue"};
console.log(haq)
12
Create a JSON file from
this data.
Firstname : bishrul
Lastname : Haq
Age : 24
Address :
streetAddress : 23/1 York Street
city : Badulla
state : Uva
PhoneNumber :
type : home
number : 000 000000
Gender :
type: maleBH | JSON
13
You can use both the brackets or dot notations to add or get data.
BH | JSON
var bh= {}
bh.car1 = “black”
bh["car1"] = “blue”
console.log(bh);
14
The JSON.stringify() method converts a JavaScript 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.
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.
BH | JSON
var bh = {“firstname” : “Bishrul”, “lastname” : “haq”};
var obj = JSON.parse(json);
console.log(obj);
var bh ={ x: 5, y: 6 };
var obj = JSON.stringify(json);
console.log(obj);
15
• Create an object as shown below.
• Output the content in the console.
• Add it to your localhost using JavaScript.
BH | JSON
Person
Firstname : bishrul
Lastname : Haq
Age : 24
Firstname : bishrul
Lastname : Haq
Age : 20
16
If you have any questions or suggestions
please connect with me via an email.
info@bishrulhaq.com
BH | JSON

More Related Content

What's hot (8)

3DRepo
3DRepo
MongoDB
 
NoSQL with MongoDB
NoSQL with MongoDB
Ikram Manseri
 
Regular Expressions in JavaScript and Command Line
Regular Expressions in JavaScript and Command Line
Mandi Grant
 
Adressing modes of 8086
Adressing modes of 8086
KANNANKR12
 
Ch03 Mining Massive Data Sets stanford
Ch03 Mining Massive Data Sets stanford
Sakthivel C R
 
3D + MongoDB = 3D Repo
3D + MongoDB = 3D Repo
MongoDB
 
8086 addressing modes
8086 addressing modes
HarshitParkar6677
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing support
Alexander Korotkov
 
Regular Expressions in JavaScript and Command Line
Regular Expressions in JavaScript and Command Line
Mandi Grant
 
Adressing modes of 8086
Adressing modes of 8086
KANNANKR12
 
Ch03 Mining Massive Data Sets stanford
Ch03 Mining Massive Data Sets stanford
Sakthivel C R
 
3D + MongoDB = 3D Repo
3D + MongoDB = 3D Repo
MongoDB
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing support
Alexander Korotkov
 

Similar to JSON in JavaScript (20)

Json
Json
krishnapriya Tadepalli
 
CS8651 IP Unit 2 pdf regulation -2017 anna university
CS8651 IP Unit 2 pdf regulation -2017 anna university
amrashbhanuabdul
 
Json training
Json training
Elavarasi Dc
 
JSON - (English)
JSON - (English)
Senior Dev
 
Java script and json
Java script and json
Islam Abdelzaher
 
Unit-2.pptx
Unit-2.pptx
AnujSood25
 
Json
Json
baabtra.com - No. 1 supplier of quality freshers
 
Introduction to JSON
Introduction to JSON
Kanda Runapongsa Saikaew
 
Json
Json
Anderson Oliveira
 
json.ppt download for free for college project
json.ppt download for free for college project
AmitSharma397241
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
Sanjeev Kumar Jaiswal
 
Json
Json
Steve Fort
 
JSON
JSON
Zara Tariq
 
Intro to JSON
Intro to JSON
George McKinney
 
Json
Json
baabtra.com - No. 1 supplier of quality freshers
 
Json
Json
soumya
 
Java Script Object Notation (JSON)
Java Script Object Notation (JSON)
Adnan Sohail
 
java script json
java script json
chauhankapil
 
JSON.pptx
JSON.pptx
MaheshHirulkar1
 
All about XML, JSON and related topics..
All about XML, JSON and related topics..
tinumanueltmt
 
Ad

Recently uploaded (20)

How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Sustainable Innovation with Immersive Learning
Sustainable Innovation with Immersive Learning
Leonel Morgado
 
GEOGRAPHY-Study Material [ Class 10th] .pdf
GEOGRAPHY-Study Material [ Class 10th] .pdf
SHERAZ AHMAD LONE
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
Ad

JSON in JavaScript

  • 2. • Extended from the javascript • JSON is a language-independent data format • Media type is application/json • extension is .json 2BH | JSON
  • 3. 3 1. Always starts and ends with curly brackets { } name and value is separated by a colon : more than one pair is separated by comma. 2. It is the most common data format used for asynchronous browser/server communication, largely replacing XML which is used by AJAX. 3. For arrays put the arrays between [ ]. 4. For elements put the values directly separated by commas. BH | JSON
  • 4. key/name value pairs • { "name" : "value" } 4 Objects are comma separated • { "name1" : "value" , "name2" : "value", "name3" : "value"} Arrays have square brackets with values separated by comma • { "name" : [ { "name" : "value" }, { "name" : "value" }] } BH | JSON
  • 5. In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. 5 • Collection of name/value pairs : Think Object format • Ordered list of values : Think Array format BH | JSON
  • 6. Number - double- precision floating-point can be digits, positive or negative, decimal fractions, exponents. • {"name": 10} 6 String - double-quoted Unicode with backslash escaping • {"name": "Hello world"} Boolean - true or false • {"name": true} Array - ordered sequence of values uses square brackets. Values are each separated by a comma. Indexing starts with 0. • {"name": [{"name1": 1}, "hello", "world"]} BH | JSON
  • 7. 7 Object - unordered collection with key:value pairs. Wrapped with curly brackets {}. Colons to separate key and name. Keys should be strings and have unique names. • {"name": {"name1": 1,"name2": 1}} Null - just empty • {"name": null} BH | JSON
  • 8. 8 JSON is an object which can be used to describe something. Two items with one value described. • { "car1": "black", "car2": "blue" } JSON vs XML JSON and XML are human readable formats JSON is faster to write. XML has not arrays. JSON much easier to parse in JavaScript BH | JSON
  • 9. var detail = { “firstname“ : “Bishrul", “lastname" : “Haq", “age“ : 24 }; Console.log ( detail ); Open up your ide. Create an object Output the Object (Try in using your browser). 3 2 1 BH | JSON 9
  • 10. 10 Another good advantage of JSON is the ability to pass the value or data into a JavaScript object. var o = { foo: "bar" }; { "foo": "bar" } • JSON has double quotes while JavaScript can use single or doubles. • JavaScript can include functions which is not available in JSON. BH | JSON
  • 11. 11 Here are some examples for objects in JavaScript: var haq= {}; haq.car1 = "black" console.log(haq) haq.car2 = "blue“ console.log(haq) BH | JSON var haq = {}; haq["car1"] = "black“ console.log(haq) haq["car2"] = "blue“ console.log(haq) var haq = {"car1" : "black" ,"car2" : "blue"}; console.log(haq)
  • 12. 12 Create a JSON file from this data. Firstname : bishrul Lastname : Haq Age : 24 Address : streetAddress : 23/1 York Street city : Badulla state : Uva PhoneNumber : type : home number : 000 000000 Gender : type: maleBH | JSON
  • 13. 13 You can use both the brackets or dot notations to add or get data. BH | JSON var bh= {} bh.car1 = “black” bh["car1"] = “blue” console.log(bh);
  • 14. 14 The JSON.stringify() method converts a JavaScript 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. 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. BH | JSON var bh = {“firstname” : “Bishrul”, “lastname” : “haq”}; var obj = JSON.parse(json); console.log(obj); var bh ={ x: 5, y: 6 }; var obj = JSON.stringify(json); console.log(obj);
  • 15. 15 • Create an object as shown below. • Output the content in the console. • Add it to your localhost using JavaScript. BH | JSON Person Firstname : bishrul Lastname : Haq Age : 24 Firstname : bishrul Lastname : Haq Age : 20
  • 16. 16 If you have any questions or suggestions please connect with me via an email. [email protected] BH | JSON