json & xml by mathura shreedher sridhar. xml introduction xml stands for “extensible markup...

75
JSON & XML BY Mathura Shreedher Sridhar

Upload: milo-lindsey

Post on 22-Dec-2015

251 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON & XML

BYMathura Shreedher Sridhar

Page 2: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML

Page 3: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Introduction

• XML stands for “Extensible Markup Language”.• XML provides set of rules for encoding

documents.• XML is a general approach to represent all

types of information such as data sets, spread sheets, graphic displays etc.,

• XML provides the basic, common and simple structure or syntax to describe new formats.

Page 4: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Introduction

• XML was designed to describe the data.• XML was not designed to display the data but

HTML is.• XML is software and hardware independent

tool for carrying information.

Page 5: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Specifications

• The first version XML 1.0 was initially defined in 1998.

• The current 5th edition of XML 1.0 was published on November 26, 2008.

• The next version XML 1.1 was published on February 4, 2004.

• It’s current 2nd edition was published on August 16, 2006.

Page 6: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

History

• XML is derived from SGML (Standard Generalized Markup Language).

• SGML’s utility to www was recognized in the early 1980’s and SGML was included in W3C’s list of activities.

• XML was compiled by a group of 11 members supported by 150-member interest group.

Page 7: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

History

• XML working group communicated virtually and the design was accomplished by the combination of email and weekly conferences.

• First working draft of XML was published in 1996.

• XML 1.0 became a W3C recommendation on February 10, 1998.

Page 8: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

History

• The other names proposed to XML were MAGMA (Minimal Architecture for Generalized Markup Applications), SLIM (Structured Language for Internet Markup) and MGML (Minimal Generalized Markup Language).

Page 9: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Key Constructs in XML

• Character: XML document is a string of characters. All Unicode characters can appear in XML.

• Processor and Application: The processor otherwise called XML Parser analyzes the markup and passes the structured information to an application.

Page 10: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Key Constructs in XML

• Markup and Content: markups begin with “<“ and end with “>” or begin with “&” and end with “;”. In CDATA section the delimiters <![CDATA[ and ]]> are markup. Whitespace before and after outermost element is classified as markup. The text between the markup is classified as content.

• Tag: markup construct that begins with “<“ and ends with “>”.

Page 11: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Key Constructs in XML

Tags are of 3 types: - start tag =>Ex:<section> - end tag => Ex: </section> - empty tag => <line-break/>• Elements: A logical document component with

start tag and end tag or empty tag. The text between start tag and end tag is called content. Ex: <author>Joe</author>

Page 12: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Key Constructs in XML

• XML Declaration: XML documents may begin by declaring some information about themselves as below<?xml version="1.0" encoding="UTF-8"?>

Page 13: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Additional Info

• XML tags are not predefined. You should define your own tags.

• XML tags can consist of international characters.

• XML is just a piece of information wrapped in tags.

• XML supports data sharing by storing the data in plain text format.

Page 14: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML document structure

• XML document forms a tree structure that start at root and branches to leaves.

Example:<?xml version="1.0" encoding="UTF-8"?>

<note> <to>Tom</to> <from>Harry</from> <heading>Hi</heading> <body>Hello to Tom!</body></note>

Page 15: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML document structure

• Root element => note.• 4 child elements => to, from, heading , body.

Page 16: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Entity References

• Some characters like <, > have special meaning in XML. If they are placed inside an XML element the XML parser will throw an error. For example

<message> 5 > 3 </message> will generate an error. To avoid this error replace “>” in XML content with entity reference.

Page 17: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Entity References

• There are 5 pre-defined entity references in XML.

Entity Reference Symbol Description

&lt; < Less than

&gt; > Greater than

&amp; & Ampersand

&apos; ‘ Apostrophe

&quot; “ Quotation mark

Page 18: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Syntax Rules

• All elements must have a closing tag.• XML tags are case sensitive.• Tag names cannot contain special characters like

space, !"#$ etc. It cannot start with -,. or numeric digit

• XML elements must be properly nested.• XML documents must have a root element.• XML attribute values must be quoted.• Entity references are properly used.

Page 19: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Syntax Rules

• The syntax for writing comments is <!-- Comment --> .

• Whitespace is not truncated in XML.• XML should contain only properly encoded

Unicode characters• XML document which satisfies all the above

mentioned syntax rules is called “well formed” xml.

Page 20: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

• XML namespaces helps to avoid naming conflicts.

• Naming conflicts occur when trying to mix XML documents from different XML applications.

• Example follows: Courtesy: http://www.w3schools.com/xml

Page 21: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

• XML1:This XML carries information about HTML table .

<table> <tr> <td>Apples</td> <td>Bananas</td> </tr>

</table>

Page 22: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

• XML2: This XML carries information about a table (piece of furniture) <table>

<name>African Coffee Table</name> <width>80</width> <length>120</length>

</table>

• If these 2 XML fragments are mixed together, this will return in naming conflicts.

Page 23: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

• Solve the name conflict using prefix.<h:table>

<h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr>

</h:table>

Page 24: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

<f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length>

</f:table>• Now there will be no conflicts as two table

names are different.

Page 25: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces

• Define namespace using xmlns attribute.• The namespace declaration has the following

syntax. xmlns:prefix="URI".

Page 26: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Namespaces• Ex: <root>

<h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr></h:table>

<f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length></f:table>

</root>

Page 27: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Valid XML documents

• A valid XML document must be well formed.• A valid XML document must conform to a

document type.• A document type or document definition or

document schema is the set of rules that defines legal elements and attributes for XML documents.

Page 28: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Valid XML documents

• There are different types of document definitions:- Document Type Definition (DTD)

- XML Schema

Page 29: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML DTD

• A valid XML document is a “well formed” document that conforms to the rules of DTD.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE note SYSTEM "Note.dtd"><note><to>Tom</to><from>Harry</from><heading>Hi</heading><body>Hi to Tom!</body></note>

Page 30: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML DTD

• The DOCTYPE declaration in the above code contains reference to external dtd file. The dtd file can give the structure of the XML document like this.

<!DOCTYPE note[<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]>

Page 31: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML DTD

• The “!DOCTYPE note” defines that the root of the xml document is note.

• Root element “note” contains 4 child elements : to, from, heading and body.

• 4 child elements are of type “#PCDATA”.• #PCDATA means parseable text data.

Page 32: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema

• XML schema is XML-based grammar declaration and gives the structure of an XML document.

• An XML document that follows the syntax rules and validated against XML Schema is “Well Formed” and “Valid”.

Page 33: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema Example

<xs:schema version=“1.0” xmlns:xs=http://www.w3.org/2001/XMLSchema><xs:complexType name=“customer”><xs:sequence><xs:element name=“email” type=“xs:string” minOccurs=“0”/><xs:element name=“phoneNumber” type=“xs:string”minOccurs=“0”/>

Page 34: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema Example

</xs:sequence><xs:attribute name=“first_name” type=“xs:string”/><xs:attribute name=“last_name” type=“xs:string”/></xs:complexType></xs:schema>

Page 35: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema Elements and Attributes

• schema – root element of every XML Schema. Contains attributes such as schema version.

• xmlns – xml namespace. Each element in the schema has default prefix xs which is associated with xmlns.

• element – xml schema element.• type – an element can be of any simple type

such as string, long, double.

Page 36: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema Elements and Attributes

• minOccurs, maxOccurs – Define the minimum and maximum occurrence of a type. This value may be a positive integer or term unbounded to indicate there is no maximum number of occurences.

• complexType – complexType can contain elements, subelements and attributes. A complexType can contain another complexType.

Page 37: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Schema Elements and Attributes

• sequence – An element may include other elements called child elements. The sequence element specifies that child element must appear in sequence.

• attribute – a complexType can have one or more attributes.

• choice – Used to indicate only one set of elements can be present in the containing element.

Page 38: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Parser

• XML Parser is a software library or package that provides interface methods to the client to work with XML documents.

• XML Parser checks the “well formed”ness of XML document.

• XML Parser validates the XML document using XML schema or DTD.

Page 39: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

XML Parser

In this presentation 2 general parsers will be discussed:• DOM Parser• SAX Parser

Page 40: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

DOM Parser

• DOM stands for Document Object Model• DOM Parser consists of DOM document object

which contains all the information about XML document.

• DOM Parser provides tree structure of an object

Page 41: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

DOM Parser

<?xml version="1.0"?> <?xml-stylesheet type="text/css" href=“test.css"?> <!-- It's an xml-stylesheet processing instruction. --> <!DOCTYPE shapes SYSTEM “shapes.dtd"> <shapes> …… <square color=“BLUE”> <length> 20 </length> </square> …… </shapes>

Page 42: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

DOM Parser

Page 43: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

DOM Parser

• DOM Parser creates an internal structure like the above in memory which is DOM document object.

• Information about the XML document can be retrieved by invoking methods on this document object.

• DOM Parsers store the document object in memory.

Page 44: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

SAX Parser

• SAX stands for Simple API for XML.• SAX is an event based sequential access parser

API.• The SAX event includes: XML Text nodes, XML

Elements Starts and Ends, XML Processing instructions and XML Comments.

• The user defines a number of callback methods that will be called when events occur during parsing

Page 45: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

SAX Parser

• SAX is the fastest XML parsing method and is suitable for handling large documents that could not be read into memory all at once.

Page 46: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

How XML can be used?

• Separate data from HTML using XML. Store data in XML file and use HTML only to display data. Any change in the data will not affect HTML file.

• Use XML for data transport between different systems over internet. XML data can be read by different incompatible applications.

• XML is plain text. Hence it is easy to store in software and hardware independent way.

Page 47: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Applications of XML

• Several document formats have been developed using XML. Eg: RSS, Atom, SOAP and XHTML.

• XML-based formats have become the default of many office productivity tools such as MS-Office, OpenOffice.org.

• XML has been employed as the base language of many communication protocols such as XMPP.

Page 48: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Applications of XML

• Configuration files for Microsoft .Net framework was done using XML.

• Apple has an implementation of a registry (property list files) based on XML.

• XML has been used as common interchange format in internet.

Page 49: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON

Page 50: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Introduction

• JSON stands for JavaScript Object Notation.• JSON is a text-based open standard format or

syntax used for storing and exchanging data.• It is primarily used to transmit data between

server and web application.• It is designed to be easier to use alternative to

XML.

Page 51: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Introduction

• JSON is derived from Javascript language. No extra software is needed to work with JSON in Javascript.

• It is language independent and can be implemented with most of the modern programming languages.

• JSON transmits objects in the form of attribute:value pairs.

• JSON is currently described by 2 competing standards RFC 7159 and ECMA – 404.

Page 52: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Introduction

• The internet media type for JSON is application/json.

• The JSON file extension is .json .

Page 53: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

History

• The term JSON was coined by Douglas Crockford at his company State Software Inc founded in 2001 along with 5 of his colleagues.

• The JSON.org website was launched in 2002.• Yahoo started using JSON at it’s web services in

2005.• In 2006, Google started JSON in it’s Gdata web

protocol.

Page 54: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON specification

• JSON has no version number.• Since JSON is very stable, no revisions to the

JSON grammar are anticipated.

Page 55: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Basic Data types

• Number – signed number both integer and floating point. Does not allow NaN.

• String – sequence of zero or more Unicode characters enclosed with in double quotes.

• Boolean – true or false values.

Page 56: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Basic Data types

• Object – name/value pairs. Object are delimited with curly braces, commas are used to separate each name/value pair and with in each pair “:” separates name or key from value.

• Null – an empty value, using the word null.• Array – Ordered list of zero or more values.

Use [] notation with comma to separate elements.

Page 57: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Additional Info

• JSON supports four whitespace characters: the space, horizontal tab, line feed and carriage return.

• JSON ignores whitespace around syntactic elements

• JSON does not provide or allow any comment syntax.

• JSON does not support native data types such as Date, Error, Regular Expression and Function.

Page 58: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON representation example

Example Courtesy: http://en.wikipedia.org/wiki/JSON

var person = {“firstName”:”John”,“lastName”:”Smith”,“isAlive”:true,“age”:25,“height”:167.6,

Page 59: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON representation example

“address”:{“streetAddress”:”21 XYZ Street”, “city”:”New York”,“state”:”NY”,“postalCode”:”10021-0031”

},

Page 60: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON representation example

“phoneNumbers”:[{“type”:”home”,“number”:”222-222-2222”},{“type”:”office”,“number”:”333-333-3333”}],

Page 61: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON representation example

“children”:[],“spouse”:null

}

Page 62: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON Methods

• JSON.parse()• JSON.stringify()

Page 63: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON.parse(text)

• parse() method converts the string information passed to it as an object.

• Demo courtesy: http://www.w3schools.com/json/

Page 64: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON.stringify(object)

• stringify() converts JSON object into string.• Demo courtesy:

http://www.w3schools.com/json/

Page 65: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Using Javascript in JSON

• Javascript function eval() is used to parse JSON data.

• Older browsers without the support for JSON.parse() use eval() function.

• eval() does the same job as JSON.parse().

Page 66: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON Schema

• JSON schema specifies the structure of JSON data for validation, documentation, and interaction control.

• It provides contract for JSON data required by any application.

• JSON schema is JSON based and is built on similar principles as XML Schema Definition (XSD).

Page 67: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON Schema Example

Example Courtesy: http://en.wikipedia.org/wiki/JSON{

“$schema”: “http://json-schema.org/draft-03/schema#”“name”:”Product”“type”: “object”“Properties”:{

“id”:{

Page 68: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON Schema Example

“type”:”number”“description”:”Product identifier”“required”:true

},“name”:{

“type”: “string”“description”: “Name of the product”“required”: true

}}

Page 69: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON Schema Example

Below data can be validated with the above schema.

{id:1,Name:”Foo”

}

Page 70: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Applications of JSON

• JSON-RPC an RPC protocol built on JSON.• JSON is used in AJAX(client side web

development technique).• It is used to transmit data between server and

web application.

Page 71: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

JSON in NoSQL DBs

• JSON is used in NoSQL DBs such as Elastic search, CouchDB, RavenDB, MarkLogic Server, JasDB, RaptorDB, EJDB, SDB, Riak, Scalien, Pincaster, RaptorDB, InfoGrid, ArangoDB and VaultDB.

• JSON’s name/value type of storage made it possible to be used as a storage format in NoSQL DBs.

Page 72: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Comparison between JSON & XMLXML JSON

Simplicity XML is a text-based format. JSON is a text-based format.

Self-describing XML data format is self-describing.

JSON data format is self-describing.

Extensibility XML supports both primitive data formats like number, string and complex data formats like class.

JSON supports only primitive data formats like number, string.

Interoperability XML’s support of complex data type like classes make it less interoperable.

JSON’s strict support of only primitive data type make it more interoperable.

Openness XML follows open standard JSON is open. It is simple and not subject to standardization struggles

Page 73: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Comparison between JSON & XMLXML JSON

Internationalization XML uses unicode characters.

JSON uses unicode characters.

Parser DOM, SAX parsers are used to parse XML

Parsed by a standard JavaScript function

Page 74: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Why JSON is gaining attention?

JSON is faster and easier than XML:With XML• First, fetch an XML document• Then, use XML DOM parser and loop through the

document• Retrieve values and store in a variableWith JSON• Fetch a JSON string• JSON.Parse the JSON string and start using the object

Page 75: JSON & XML BY Mathura Shreedher Sridhar. XML Introduction XML stands for “Extensible Markup Language”. XML provides set of rules for encoding documents

Questions ?