Json (Javascript Object Notation) : B.Anirudh 08071A1208

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18
At a glance
Powered by AI
JSON is a lightweight data interchange format used to transmit data between a server and web application. It serves as an alternative to XML for serializing and transmitting structured data.

JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. It is derived from JavaScript for representing simple data structures and associative arrays.

The basic data types in JSON are number, string, boolean, array, object and null.

JSON (JavaScript Object Notation)

B.ANIRUDH 08071A1208

Contents
1. 2. 3. 4. 5. 6. 7. 8. 9. ABSTRACT HISTORY JSON STRUCTURE DATA TYPES XML TO JSON JSON OVER XML JSON SCHEMA JSON IN JAVA SCRIPT CONCLUSION

Abstract
JSON ( JavaScript Object Notation) is a lightweight textbased open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays. The JSON format was originally specified by Douglas Crockford, and is described in RFC 4627. The official Internet media type for JSON is application/json. The JSON filename extension is .json. The JSON format is often used for serializing and transmitting structured data over a network connection. It is used primarily to transmit data between a server and web application, serving as an alternative to XML.

History
Douglas Crockford was the first to specify and popularize the JSON format. JSON was used at State Software, a company co-founded by Crockford, starting around 2001. The JSON.org website was launched in 2002. In December 2005, Yahoo! began offering some of its web services in JSON. Google started offering JSON feeds for its web protocol in December 2006.

JSON Structure
JSON is built on two structures 1. 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. e.g.: An object with three properties named "a", "b , and "c" { "a":1,"b":2,"c":3 } 2. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. e.g.: An array of three integers and one string value [ 1, 2, 3, "value #4 with" ]

Data Types
JSON's basic types are: Number String Boolean (true or false) Array (an ordered sequence of values, commaseparated and enclosed in square brackets; the values do not need to be of the same type) Object (an unordered collection of key :value pairs with the ':' ) null(empty)

XML TO JSON
<?xml version="1.0" encoding="UTF-8" ?> <firstName>John</firstName> <lastName>Smith</lastName> <age>25</age> <address> <streetAddress>21 2nd Street</streetAddress> <city>New York</city> <state>NY</state> <postalCode>10021</postalCode> </address> <phoneNumber> <type>home</type> <number>212 555-1234</number> </phoneNumber> <phoneNumber> <type>fax</type> <number>646 555-4567</number> </phoneNumber> } { "firstName": "John", "lastName" : "Smith", "age" : 25, "address" : { "streetAddress": "21 2nd Street", "city" : "New York", "state" : "NY", "postalCode" : "10021" }, "phoneNumber": [ { "type" : "home", "number": "212 555-1234" }, { "type" : "fax", "number": "646 555-4567" } ]

JSON over XML


Lighter and faster than XML as on-the-wire data format JSON objects are typed while XML data is type less JSON types: string, number, array, boolean, XML data are all string Native data form for JavaScript code

JSON vs. XML in AJAX Application)


JSON produces slightly smaller documents JSON is easier to use in JavaScript Parsing JSON encoded data is much faster than parsing XML encoded data

XML vs. JSON (in AJAX Application)


JSON produces slightly smaller documents JSON is easier to use in JavaScript Parsing JSON encoded data is much faster than parsing XML encoded data

Schema
There are several ways to verify the structure and data types inside a JSON object, much like an XML schema; however unlike XML schema, JSON schemas are not widely used. Additionally JSON Schema have to be written manually. JSON Schema is a specification for a JSON-based format for defining the structure of JSON data. JSON Schema provides a contract for what JSON data is required for a given application and how it can be modified, much like the XML Schema provides for XML. JSON Schema is intended to provide validation, documentation, and interaction control of JSON data.

JSON SCHEMA
JSON SCHEMA
{ "name":"Product", "properties": { "id": { "type":"number", "description":"Product identifier", "required":true }, "name": { "type":"string", "description":"Name of the product", "required":true } } }

JSON SCRIPT
{ "id": 1, "name": vnr }

JSON IN JAVA SCRIPT


Creating Object in JavaScript using JSON We can create objects in JSON with JavaScript in many ways : 1. "var JSONObjectName ={};" will create an empty object. 2. "var JSONObjectName= new Object();" will create a new Object. 3. "var JSONObjectName = { "name ":"amit", "age":23}; will create an Object with attribute name which contains value in String and age with numeric value. Now by creating this object we can access attributes by only "." operator.

JSON IN JAVA SCRIPT


<html> <head> <title> Object creation in JSON in JavaScript </title> <script language="javascript" > var JSONObject = { "name" : "Amit", "address" : "B-123 Bangalow", "age" : 23, "phone" : "011-4565763", "MobileNo" : 0981100092 }; document.write("<h2><font color='blue'>Name</font>::" +JSONObject.name+"</h2>"); document.write("<h2><font color='blue'>Address</font>::" +JSONObject.address+"</h2>"); document.write("<h2><font color='blue'>Age</font>::" +JSONObject.age+"</h2>"); document.write("<h2><font color='blue'>Phone No.</font>::" +JSONObject.phone+"</h2>"); document.write("<h2><font color='blue'>Mobile No.</font>::" +JSONObject.MobileNo+"</h2>"); </script> </head> <body> <h3>Example of object creation in JSON in JavaScript</h3> </body> </html>

JSON IN JAVA SCRIPT

CONCLUSION
Currently, JSON is very young but it has a very bright future. It is the most efficient way of representing data that that is being exchanged over a network connection in terms of ease of use and speed of processing. JSON is also very flexible and can be used with almost any programming language. These factors make JSON a very attractive alternative to XML. JSON is continuously gaining ground and getting more attention in the world of web applications. Today, most web browsers, including Firefox 3.5, Internet Explorer 8, and Safari, all run native JSON.

ANY QUERIES

??

THANK YOU

You might also like