Top Banner
JSON The Fat Free Alternative to XML
26

JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Dec 27, 2015

Download

Documents

Branden Perry
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSONThe Fat Free

Alternative to XML

Page 2: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Data Interchange

• The key idea in Ajax.

• An alternative to page replacement.

• Applications delivered as pages.

• How should the data be delivered?

Page 3: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

History of Data Formats

• Ad Hoc

• Database Model

• Document Model

• Programming Language Model

Page 4: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON

• JavaScript Object Notation

• Minimal

• Textual

• Subset of JavaScript

Page 5: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON

• A Subset of ECMA-262 Third Edition.

• Language Independent.

• Text-based.

• Light-weight.

• Easy to parse.

Page 6: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON Is Not...

• JSON is not a document format.• JSON is not a markup language.• JSON is not a general serialization

format. No cyclical/recurring structures. No invisible structures. No functions.

Page 7: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

History

• 1999 ECMAScript Third Edition

• 2001 State Software, Inc.

• 2002 JSON.org

• 2005 Ajax

• 2006 RFC 4627

Page 8: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

MIME Media Type

application/json

Page 9: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Languages

• Chinese• English• French• German• Italian• Japanese• Korean• Spanish

Page 10: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Languages

• ActionScript• C / C++• C#• Cold Fusion• D• Delphi• E• Erlang• Haskell• Java• Lisp

• LotusScript• Lua• Perl• Objective-C• OCAML• PHP• Python• Rebol• Ruby• Scheme• Squeak

Page 11: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Values

• Strings• Numbers• Booleans

• Objects• Arrays

• null

Page 12: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Value

number

string

value

object

false

null

array

true

Page 13: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Strings

• Sequence of 0 or more Unicode characters

• No separate character type A character is represented as a string

with a length of 1

• Wrapped in "double quotes"• Backslash escapement

Page 14: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Stringstring

"Any UNICODE character except" or \ or control character

\ "

\

quotation mark

reverse solidus

/solidus

bbackspace

formfeed

newline

carriage return

horizontal tab

4 hexadecimal digits

f

n

r

t

u

"

Page 15: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Numbers

• Integer• Real• Scientific

• No octal or hex• No NaN or Infinity

Use null instead

Page 16: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Number

number

digit 1 - 9

.0

digit

e

E

digit

-

digit

+

-

Page 17: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Booleans

• true• false

Page 18: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

null

• A value that isn't anything

Page 19: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Object

• 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

Page 20: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Object

{ : }valuestring

object

,

Page 21: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Object{ "name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 }}

Page 22: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Versionless

• JSON has no version number.

• No revisions to the JSON grammar are anticipated.

• JSON is very stable.

Page 23: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON is the X in Ajax

Page 24: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON in Ajax

• HTML Delivery.

• JSON data is built into the page. <html>... <script> var data = { ... JSONdata ... }; </script>... </html>

Page 25: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

JSON in Ajax

• XMLHttpRequest Obtain responseText Parse the responseText

responseData = eval( '(' + responseText + ')');

responseData = responseText.parseJSON();

Page 26: JSON The Fat Free Alternative to XML. Data Interchange The key idea in Ajax. An alternative to page replacement. Applications delivered as pages. How.

Some features that make it well-suited for data transfer

• It's simultaneously human- and machine-readable format;

• It has support for Unicode, allowing almost any information in any human language to be communicated;

• The self-documenting format that describes structure and field names as well as specific values;

• The strict syntax and parsing requirements that allow the necessary parsing algorithms to remain simple, efficient, and consistent;

• The ability to represent the most general computer science data structures: records, lists and trees.