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

Liet - Json

This document provides an introduction to JSON (JavaScript Object Notation). It describes what JSON is, how it is structured as a data format, and how it can be used with JavaScript, Java, PHP, AJAX, and for REST APIs. Examples are given of how JSON data looks and how it is lighter weight and easier to consume than XML, making it well suited for REST and AJAX applications.

Uploaded by

aloshbennett
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Liet - Json

This document provides an introduction to JSON (JavaScript Object Notation). It describes what JSON is, how it is structured as a data format, and how it can be used with JavaScript, Java, PHP, AJAX, and for REST APIs. Examples are given of how JSON data looks and how it is lighter weight and easier to consume than XML, making it well suited for REST and AJAX applications.

Uploaded by

aloshbennett
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 10

An Introduction to JSON

LIET Session
Alosh Bennett
What is JSON?

 JavaScript Object Notation


 Collection of Attributes
 Arrays

 Data representation format


 Human Readable
 Lightweight
 Inter-changeable

 Similar role as XML

 Primary use over the net


What does it look like?

 Object: collection of comma separated attributes


 var object = { }

 Attributes: name-value pairs


 “name”: “Duke”
 “age”: 10

 Array: List of comma separated objects


 [{“name”: “Duke”, “age”: 10}, {name=“Tux”, “age”: 20}]

 Data types
 (String, Number, boolean, array, object, null)
What does it *really* look like?

{
"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" }
]
}
Okay, so what buttons to press?

 JavaScript
 Direct consumption
 var person = {“name”: “Duke”, “age”: 10};
 eval() function
 var person = eval(‘({“name”: “Duke”, “age”: 10})’);
 Parse()
 var person = JSON.parse(‘{“name”: “Duke”, “age”: 10}’);

 Java
 Open source libs from JSON.org
 new JSONObject().put(“name", “Duke") ;

 No JSR yet to bring JSON support into Java SE specs

 PHP
 Native support starting PHP5
Fly JSON fly!

REST services
Returning JSON + javascript consuming JSON
as native objects

Super Fast
Extremely easy
AJAXy
Consumption of WS from browser
JSON and AJAX

 XMLHttpRequest
 Standard way of invoking WS from JS
 Limited by same–origin Policy

 JSONP
 Invocation using <script> tag
 Bypasses same-origin policy
If you put JSON and XML in a cage..

 JSON is usually smaller in size on the wire JSON

 (If attributes are used instead of tags, XML can be smaller)


 JSON is easier to consume from web pages JSON
 In JSON, its easier to distinguish JSON

 text-that-looks-like-number and number


 Strings can contain control characters
XML
 XML is bound by an extendable, referable schema (XSD)
 (There is a proposal for introducing schema to JSON)
XML
 XML has standard implementations for XPath, Xlink, XSLT
 (JSON has open source implementations available, but no single standard)
 XML brings semantics to data by bringing namespaces and URIs XML

 In Short,
 JSON hits the sweet spot in REST + AJAX scenario
 XML is advisable when a more formal stricter data representation is
required.
JSON in the wild

 GeoJSON
 Open format for representing geographic data based on JSON

 JSON-RPC
 JSON based protocol for RPC invocation over http (or other)

 SOAPjr
 SOAP + JSON-RPC. SOAP model envelope/header/body in JSON format

 Google Data Services


 Supports JSON as data format

 Apache CouchDB
 Provides RESTful JSON API

 MongoDB
 Provides RESTful JSON API

 Flickr
 Provides RESTful JSON API
Thank you!

{
“LIET”: “JSON”,
Status: “Q&A”
}

You might also like