Liet - Json
Liet - Json
LIET Session
Alosh Bennett
What is JSON?
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") ;
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..
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
Apache CouchDB
Provides RESTful JSON API
MongoDB
Provides RESTful JSON API
Flickr
Provides RESTful JSON API
Thank you!
{
“LIET”: “JSON”,
Status: “Q&A”
}