Automatically Generating JSON from Java Objects Java Objects
JSON – Java Script Object Notation_Swati_Kumar
-
Upload
angshusmita-baruah-segra -
Category
Documents
-
view
221 -
download
0
Transcript of JSON – Java Script Object Notation_Swati_Kumar
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
1/15
JSON
Java Script Object
Notation
Swati Kumar
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
2/15
What is JSON
JSON is a data interchange format
Interactive Web 2.0 applications, no more
use page replacement. Data transfer without
refreshing a page.
The most important aspects of data transfer
are simplicity, extensibility, interoperability,
openness and human readability Key idea in AJAXAsynchronous Java
Script and XML.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
3/15
Topics to cover
Overview of the working of JSON
Properties of JSON as a data format
JSON with AJAX
Advantages of using JSON with AJAX
Security Concerns in using JSON
Where does it fit the best
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
4/15
How does it work?
JSON is a subset of Java Script. JSON canbe parsed by a Java Script parser.
It can represent either complex or simple
data as it has data types They are Strings, Number, Boolean, Objects
and Arrays
E.g. of Object:
{ "name": "Jack (\"Bee\") Nimble", "format": {"type": "rect", "width": 120, "interlace": false}}
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
5/15
An array can be shown as
["Sunday", "Monday", "Tuesday","Wednesday]
All data types are intuitive and similar to other
programming languages Also compatible with other languages like C,
C++, C#, ColdFusion, Python and many
more.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
6/15
Properties of JSON
It's simultaneously human- and machine-readableformat.
It has support for Unicode, allowing almost anyinformation in any human language to be communicated;
The self-documenting format that describes structureand field names as well as specific values.
The strict syntax and parsing requirements that allow thenecessary parsing algorithms to remain simple, efficient,and consistent;
The ability to represent the most general computerscience data structures: records, lists and trees.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
7/15
JSON in AJAX
JSON can be used in AJAX as follows:
Include it in HTML directly
... var data = JSONdata;
...
JSON is used with XMLHttpRequest and can
be converted into a JavaScript structure
responseData = eval('(' + responseText + ')');
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
8/15
Another approach is to use an invisible for data communication. The server
sends JSON text embedded in a script in a
document.
document.domain =
something.com; parent.deliver(JSONtext);
deliver is passed the incoming data structure.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
9/15
Why is JSON better suited for AJAX?
JSON is widely used in AJAX. The X in AJAX stands for XML.
E.g.
{
"fullname": "Swati Kumar",
"org": "Columbia", }
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
10/15
JSON response at client side is: var name = eval('(' + req.responseText +
')').fullname.value;
To access a composite element
eval('(' + req.responseText +
')').xyz.abc.value;
Thus, any level deep elements can be easily
accessed.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
11/15
XML response at client side is:
var root = req.responseXML; var name =
root.getElementsByTagName(fullname);
To access a composite element root.getElementsByTagName(xyz)[0].firstChi
ld
To access deeper levels we need moreoverhead.
Reduced extensibility in XML
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
12/15
Security Concerns
Same Origin Policy - JavaScript to access the
contents of a Webpage, both the JavaScript
and the Web page must originate from the
same domain. Malicious website could serve up JavaScript
that loads sensitive information from other
websites using a client's credentials andcommunicates it back to the attacker.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
13/15
Although the malicious JavaScript cantdirectly manipulate the contents, it can view
the execution of the JavaScript and store the
results it returns.
This problem gets aggravated with JSON as
the JSON arrays are themselves JavaScript
objects and any malicious user can view
them directly.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
14/15
Where can JSON be used?
JSON is a light weight data format that can
be used for transferring medium amounts of
data.
It can be used in Java Script and thenrendered on HTML pages
AJAX has many applications for JSON
Thus, use JSON for applications that arebrowser based.
-
8/12/2019 JSON Java Script Object Notation_Swati_Kumar
15/15
References:
www.json.org
RFC 4627, Network Working Group D.
Crockford
Thank you
http://www.json.org/http://www.json.org/