0% found this document useful (0 votes)
21 views13 pages

Session 23

JSON is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. It is built on two structures: a collection of name/value pairs and an ordered list of values. JSON supports strings, numbers, objects, arrays, true, false and null. JavaScript is a superset of JSON and JSON can be parsed into JavaScript objects for easy use.

Uploaded by

Atman Rah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views13 pages

Session 23

JSON is a lightweight data-interchange format that is easy for humans to read and write and for machines to parse and generate. It is built on two structures: a collection of name/value pairs and an ordered list of values. JSON supports strings, numbers, objects, arrays, true, false and null. JavaScript is a superset of JSON and JSON can be parsed into JavaScript objects for easy use.

Uploaded by

Atman Rah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

JSON

Venkat Subramaniam – [email protected] 1


Does Ajax need XML?
• The X in Ajax once stood for XML

• Now x is more like ? Whatever that’s


appropriate

• XML has its advantages and


disadvantages
– Very expressive, but too noisy, large, slow…

Venkat Subramaniam – [email protected] 2


JSON
• JavaScript Object Notation

• It is intended to be minimal

• It is a textual notation of data

• JavaScript is a superset of JSON


• YAML is a superset of JSON
– YAML decoder and JavaScript interpreter can
be used as JSON decoder
Venkat Subramaniam – [email protected] 3
What’s in JSON

Venkat Subramaniam – [email protected] Source: http:www/json.org 4


• Strings
String
– Any double quoted Unicode character
– Double quote escaped using \
– Empty string represented by ""

Venkat Subramaniam – [email protected] Source: http:www/json.org 5


Number
• Numbers
– Integer, real, scientific
– Use null for invalid/infinity

Venkat Subramaniam – [email protected] Source: http:www/json.org 6


Object
• Objects: More of a hashmap notation
– {"keyname": JSONValue, "keyname":
JSONValue,…}
– JSONValue may be any of the JSON value
types including other objects

Venkat Subramaniam – [email protected] Source: http:www/json.org 7


Arrays
• Arrays
– Sequence of values
– [JSONValue, JSONValue, JSONValue, …]
– Index is decided by implementation (like Java
can use 0, VB can use 1, JSON doesn’t care)
– JSONValue may be any JSON value type
including objects and arrays

Venkat Subramaniam – [email protected] Source: http:www/json.org 8


Using JSON to Populate a Page

Venkat Subramaniam – [email protected] 9


Concerns with eval
• eval sends the JSON text (or any text) to
the Java compiler

• May not be safe

• Use only if trusted source

• What’s the alternative

• parseJSON only parses JSON text


Venkat Subramaniam – [email protected] 10
parseJSON
• Available from http://
www.json.org/json.js
• Parses only JSON text and is fast

Venkat Subramaniam – [email protected] 11


Convert to JSON
• toJSONString() converts an object to
JSON

Venkat Subramaniam – [email protected] 12


More Convenience
• More convenient processing functions are
sprouting up

• There is also proposal for JSONRequest


object to be standardized by browsers
– http://json.org/JSONRequest.html

Venkat Subramaniam – [email protected] 13

You might also like