an introduction to json javascript object notation

20
www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl An Introduction to JSON JavaScript Object Notation Ahmed Muzammil | @ahmedmzl

Upload: ahmed-muzammil

Post on 19-Jan-2015

2.310 views

Category:

Technology


2 download

DESCRIPTION

JSON (JavaScript Object Notation), is a text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages. 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.

TRANSCRIPT

Page 1: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

An Introduction to JSON JavaScript Object Notation Ahmed Muzammil | @ahmedmzl

Page 2: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

What's inside

Introducing JSONWhy JSON

JSON StructuresData in JSON

JSON Arrays, ObjectsJSON Values, String, Number

Tools for DevelopersJSON Data Example

Page 3: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JavaScript Object Notation

The fat free alternative to XML

Page 4: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

Why JSON ??

• It's easy for humans to read and write

• It's also easy for computers to read and parse

• JSON's structure is significantly simple.

• Parsing efficiency is more when compared to XML

• Lighter and faster than XML as on-the-wire data format

Page 5: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON objects are "typed" vs. XML is "typeless"

JSON

string

number

boolean

array

XML

AllStrings

Page 7: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON ➡ Native data form for JavaScript

• Data is readily accessible as JSON objects

• Retrieving values from JSON is as easy as importing an object in JavaScript

• XML data needs parsing

• Needs to use tedious DOM APIs and processing power to assign to variables

Page 8: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON is built on two structures

• A collection of name/value pairs• Realization (as in various programming languages)

• Object, Record, Struct, Dictionary, HashTable, Keyed List, or Associative Array

• An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

• Realization (as in various programming languages• array, vector, list, or sequence

• JSON follows universal data structures• It is interoperable between programming languages

Page 10: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON :: Object

• Example

var myJSONObject = { “Fruits” : [ “Apple” , “Orange”, “Grapes” ], };

Page 11: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON :: Array

•Example

var myJSONArray = [ “Apple” , “Orange”, “Grapes” ];

Page 13: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON String

• A string is very much like a C or Java string. • string is a collection of zero or more Unicode characters within double

quotes and using backslash escapes• character is represented as a single character string

Eg.“Ahmed Muzammil”“\”Jamal\””“\nTest”“\uAF34\u34DS”

Page 14: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON Number

• A number is very much like a C or Java number! octal and hexadecimal formats are not used.

Eg.12345671.324320.342 e+121.23324342 e-32

Page 15: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON Tools for Developers

• Available for download @ www.json.org

• ParserParse JSON text files and convert these to a Java model

• RendererRender a Java representation into text

• SerializerSerialize plain POJO clusters to a JSON representation

• ValidatorValidate the contents of a JSON file using a JSON schema

• Tools are also available for other languages• ASP, ActionScript, C Family, ColdFusion, Delphi, JavaScript, Perl, PHP,

PL/SQL, Ruby, Symbian & many more

Page 16: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

Where is JSON Used?

• Ajax applications / Web 2.0

• Represent configuration information

• Implement communication protocols

• Data Exchange

• Remote Procedure Call / RMI

• Service Oriented Architecture

Page 17: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

Let’s end with an example JSON

{ "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“ } ]}

Page 18: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

The same Example in XML

<Object><Property><Key>firstName</Key> <String>John</String></Property> <Property><Key>lastName</Key> <String>Smith</String></Property> <Property><Key>age</Key> <Number>25</Number></Property> <Property><Key>address</Key> <Object> <Property><Key>streetAddress</Key><String>21 2nd Street</String></Property><Property><Key>city</Key> <String>New York</String></Property> <Property><Key>state</Key> <String>NY</String></Property> <Property><Key>postalCode</Key> <String>10021</String></Property></Object></Property> <Property><Key>phoneNumber</Key><Array> <Object> <Property><Key>type</Key> <String>home</String></Property> <Property><Key>number</Key> <String>212 555-1234</String></Property></Object> <Object><Property><Key>type</Key> <String>fax</String></Property> <Property><Key>number</Key> <String>646 555-4567</String></Property> </Object> </Array></Property></Object>

Page 19: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

Want more of JSON ? Go here...

• Introducing JSON - http://www.json.org/

• Introduction to JSON - http://www.javapassion.com/ajax/JSON.pdf

• JSON in JavaScript - http://www.json.org/js.html

• JSON in Java - http://www.json.org/java/index.html

Page 20: An Introduction to JSON JavaScript Object Notation

www.ahmedmzl.com | Ahmed Muzammil Jamal ] LinkedIn ] @ahmedmzl

JSON is GOOD !

• Like this presentation? Share it...

• Questions?- Tweet me @ahmedmzl

• I can help you on:• Service Oriented Architecture (SOA)• Business Process Management (BPM)• Business Intelligence (BI)• User Experience (UX)• Product Development• Project Management

Buy a "I ♥ JSON Tshirt" like this here at zazzle.com