0% found this document useful (0 votes)
38 views

JSON

The document contains two examples of JSON formatted data representing profiles of individuals named Nandita and Nancy. Each profile includes fields for name, favorite number, programmer status, hobbies, and friends. The friends field contains an embedded JSON object with additional details about that person. The document also compares key differences between JSON and XML, such as JSON being less verbose, faster to parse, and using a simpler data model than XML's tree structure. Reasons given for preferring JSON over XML include its more compact and readable style, faster parsing speed, and producing data in a ready-to-use JavaScript object format.

Uploaded by

Nandita Hans
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

JSON

The document contains two examples of JSON formatted data representing profiles of individuals named Nandita and Nancy. Each profile includes fields for name, favorite number, programmer status, hobbies, and friends. The friends field contains an embedded JSON object with additional details about that person. The document also compares key differences between JSON and XML, such as JSON being less verbose, faster to parse, and using a simpler data model than XML's tree structure. Reasons given for preferring JSON over XML include its more compact and readable style, faster parsing speed, and producing data in a ready-to-use JavaScript object format.

Uploaded by

Nandita Hans
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

JSON FORMAT

“name”:”Nandita”,

“favouriteNumber”:3,

“isProgrammer”:true,

“hobbies”:[“Music”,”Badminton”]

“friends”:[{

“name”:”Harsh”,

“favouriteNumber”:9,

“isProgrammer”:False,

“friends”:[‘Meena’,’Reena’,’Tina’]

}]

},

“name”:”Nancy”,

“favouriteNumber”:3,

“isProgrammer”:true,

“hobbies”:[“Weight Lifting”,”Bowling”]

“friends”:[{

“name”:”Harsh”,

“favouriteNumber”:null,

“isProgrammer”:False,
“friends”:[‘Meena’,’Reena’,’Tina’]

}]

<script type=”text/javascript”>

let students=

‘[

“name”:”Nandita”,

“favouriteNumber”:3,

“isProgrammer”:true,

“hobbies”:[“Weight Lifting”,”Bowling”]

“friends”:[{

“name”:”Harsh”,

“favouriteNumber”:9,

“isProgrammer”:False,

“friends”:[‘Meena’,’Reena’,’Tina’]

}]

}]’

console.log(JSON.parse(students))

</script>
DIFFERENCE b/w JSON and XML
JSON(JavaScript Object XML(Extensive Markup
Notation) Language)

1.It is based on JavaScript Language 1.It is derived from SGML(Standard


Generalized Markup Language)

2.It supports array and doesn’t use end tag. 2.It doesn’t supports array and uses start
and end tags.

3.Files are easy to ready as compared to 3. Its documents are comparatively


XML difficult to read and interpret.

4.It is a way of representing Objects 4. Its files are very easy to read as
compared to XML.

5.It’s less secured and supports only UTF- 5.It’s more secured than JSON and it
8 encoding supports various encoding .

6. XML has to be parsed with an XML 6. JSON can be parsed by a standard


parser. JavaScript function.

7. JSON supports only 7. XML support many data types such as


text,Boolean,array,object and number data text, number, images, charts, graphs etc.
type. Moreover, XML offeres options for
transferring the format or structure of the
data with actual data.

8. Using JSON 8. Using XML

 Fetch a JSON string  Fetch an XML document


 JSON.Parse the JSON string  Use the XML DOM to loop
through the document
 Extract values and store in
variables
Why do we prefer JSON over XML?
1. JSON is less verbose. JSON has a compact style than XML and it is often more
readable. The Lightweight approach of JSON can make significant improvements.

2.JSON is faster. The XML software parsing process can take a long time.JSON uses
less data overall, so you reduce the cost and increase the parsing speed.

3.JSON is straightforward and readable.

4.JSON uses a map data structure which is predictable and easy to understand data
model rather than XML’s tree.

5.XML is much more difficult to parse than JSON.JSON is parsed into a ready-to-use
JavaScript object.

You might also like