Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

JSON (JAVA SCRIPT OBJECT NOTATION)

JSON is used to transfer the data which we store from a JavaScript language.
by

Mritunjay Pandey

on 9 August 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of JSON (JAVA SCRIPT OBJECT NOTATION)

JSON
Java Script Object Notation
JSON is a lightweight data-interchange format used for storing and exchanging
text information. Much like XML but smaller than XML and easy to describe.
Definition
Introduction
JavaScript Object Notation(JSON) is

- Lightweight
- Language independent
- Open source
- Derived from JavaScript language
- Easy to transform(parse)
- Very good support with AJAX based appliaction
- Developed by
"Douglas Crockford"

human readable data format used to transform the data among the websites.
- BINARY
- TEXT
- XML
History of Transformation of data
What is XML?

XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to carry data, not to display data
XML tags are not predefined. You must define your own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation
XML
Benefits of using JSON over XML
Less Verbose, yet easy to debug (readable)
More Speed & Less Bandwidth Utilization
Less Memory Footprint, faster generation & processing
Supported in Browsers via Javascript
- XML is not well suited to data-interchange

- It doesn't match the data model of most
programming languages.

-There is another text notation that has all
of the advantages of XML, but is much
better suited to data-interchange.
Why JSON
JSON-RPC
JSON-RPC Is a remote procedure call protocol encoded in JSON.
It allows for notifications and for multiple calls to be sent to the server which may be answered out of order.
It works by sending a request to a server implementing this protocol.
All transfer types are single objects, serialized using JSON.
The receiver of the request must reply with a valid response to all received requests.
JSON-RPC-JAVA
JSON-RPC-Java is a Java implementation of the JSON-RPC protocol.
Allows JavaScript DHTML Web applications to call remote methods in a Java Application Server without the need for page reloading.
It is an enabler for the next generation of fast and highly dynamic enterprise Java Web applications.
Minimal changes are necessary to existing server-side Java code to allow calling from JavaScript.


Number - Includes integer, real, and floating point String – Supports
Unicode
Boolean - true or false
Array – It is represented as an ordered sequence of values, with each
value being
comma-separated
and enclosed in
square brackets
.
Object – Represents a collection of key/value pairs that are

comma- separated
and enclosed in
curly brackets
.
null
The basic data types in JSON
Features of JSON-RPC-Java
Dynamically call server-side Java methods from JavaScript DHTML web applications. No Page reloading.
Asynchronous communications.
Transparently maps Java objects to JavaScript objects.
Lightweight protocol similar to XML-RPC although much faster.
Leverages J2EE security model with session specific exporting of objects.
Supports Internet Explorer, Mozilla, Firefox, Safari, Opera and Konqueror.
- A collection of name/value pairs. In various languages, this
is realized as an object, record, struct, dictionary, hash
table, keyed list, or associative array.

- An ordered list of values. In most languages, this is realized
as an array, vector, list, or sequence.
JSON is built on two structures
• Objects are unordered containers
of key/value pairs
• Objects are wrapped in
{ }

,
separates key/value pairs

:
separates keys and values
• Keys are strings
• Values are JSON values
struct, record, hashtable, object
JSON Object
JSON Array
• JSON Doesn't Have Namespaces.
• JSON Has No Validator.
• JSON Is Not Extensible.
• JSON Is Not XML.
Arguments against JSON
Example
• Arrays are ordered sequences of
values
• Arrays are wrapped in []
• , separates values
• JSON does not talk about
indexing.
An implementation can start array
indexing at 0 or 1.
Example
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
Features of JSON
Accessing JSON Object by JavaSript
<html>
<body>
<h2>Create Object from JSON String</h2>
<p>
First Name: <span id="fname"></span><br />
Last Name: <span id="lname"></span><br />
</p>
<script type="text/javascript">
var txt = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';

var obj = eval ("(" + txt + ")");

document.getElementById("fname").innerHTML=obj.employees[1].firstName
document.getElementById("lname").innerHTML=obj.employees[1].lastName
</script>
</body>
</html>
Simultaneously human and machine readable.
Has a support for Unicode
Self documenting format
Strict syntax and parsing requirements
No restructuring is required
JSON and .NET Technology
Rules
A JSON decoder must accept all well-formed JSON text.
A JSON decoder may also accept non-JSON text.
A JSON encoder must only produce well-formed JSON text.
Be conservative in what you do, be liberal in what you accept from others.
Security issues in JSON
JSON Serialization and Deserialization in ASP.NET
What is Serialization
Data security
Bowser Security
JSON can be used to execute JavaScript insertion attacks against any web client that uses it.
Eval performs an unescape.
Many JSON libraries server-side can't handle doubly encoded.
What is Deserialization
Serialize and Deserialize JSON Data on .NET
Conclusion
When XML was introduced it made waves but When JSON is fully supported by the browser will make tsunamis.
Serialization is a process of converting high
level data to low level
Deserialization is a process of converting low
level data to high level
We can use DataContractJsonSerializer to serialize type instance to JSON string deserialize JSON string to type instance.

DataContractJsonSerializer is under
System..Runtime.Serialization.Json namespace.

It is included in System.ServiceModel.Web.dll in .NET Framework 3.5 and System.Runtime.Serialization in .NET Framework 4.0. We need to add it as reference.
Simple Object Person:

public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}

Serialize as JSON String:

protected void Page_Load(object sender, EventArgs e)
{
Person p = new Person();
p.Name = "Tom";
p.Age = 28;
string jsonString =
JsonHelper.JsonSerializer<person>(p);
Response.Write(jsonString);
}
Serialization Demo
Result
{"Age":28,"Name":"Tom"}
Deserialization Demo
protected void Page_Load(object sender, EventArgs e)
{
string jsonString = "{\"Age\":28,\"Name\":\"Tom\"}";
Person p = JsonHelper.JsonDeserialize<person>(jsonString);
}
Result
Assigning JSON data to a variable
var people =
{ "programmers": [
{ "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" },
{ "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" },
{ "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" }
]
}
{ "firstName":"John" , "lastName":"Doe" }
JSON Uses JavaScript Syntax
Because JSON uses JavaScript syntax, no extra software is needed to work with JSON within JavaScript.
Example:
var employees = [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName": "Jones" }
];
With JavaScript you can create an array of
objects and assign data to it like this:
The first entry in the JavaScript object array can be accessed like this:
employees[0].lastName;
The returned content will be:
Doe
The data can be modified like this:

employees[0].lastName = "Jonatan";
Accessing and modifying data
{
"ThankYou" : "
To All
"
}
{
"
Query
"
:
"
No Limits
"
}
{
"Please"
[
}
]
Being Presented By:
- Mritunjay
- Gajendra
- Roshani
Full transcript