Presentation is loading. Please wait.

Presentation is loading. Please wait.

JavaScript Object Notation

Similar presentations


Presentation on theme: "JavaScript Object Notation"— Presentation transcript:

1 JavaScript Object Notation
JSON JavaScript Object Notation

2 JavaScript Object Notation
Plain text file format Although originally derived from the JavaScript scripting language, JSON is a language-independent data format. Whitespace (outside of strings) isn't meaningful. One data type allowed per file (but often it is a container)

3 JSON string string: a sequence of zero or more Unicode characters. Strings are delimited with double-quotation marks and support a backslash escaping syntax. "Hi\nEveryone"

4 JSON Strings Which of these are JSON strings? Josh "Josh\n" "\_(^^)_/"
""

5 JSON number number: a signed decimal number that may contain a fractional part and may use exponential E notation. 4 12.5 6.022e23 -5.6

6 JSON array array: an ordered list of zero or more values, each of which may be of any type. [] [4, "Josh", true] [[], null]

7 JSON object object: an unordered collection of name/value pairs where the names (also called keys) are strings. {"name":"Josh", "age":17, "section":[1,2]}

8 JSON values (null and boolean)
null: empty value null boolean: either of the values true false

9 Example JSON File { "name":"josh", "pets": [{ "name": "zoe", "age":7,
"birthday":null, "species":"dog", "commands":["fetch", "shake", "come"] }], "employed":true }

10 JSON Schema A schema is a definition of how the data should be formatted. Schema can be used for validation. JSON schema is currently in a working draft, but is already very broadly used. Info available at: schema.org/

11 JSON Schema Questions the schema should answer: What is the data?
Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] } Questions the schema should answer: What is the data? What is id? Is name required? Can price be 0? Are all tags strings?

12 What is the data? Example JSON File { "id": 1, "name": "A green door",
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object" } What is the data? Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] }

13 What is id? Example JSON File { "id": 1, "name": "A green door",
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" } }, "required": ["id"] } What is id? Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] }

14 Is name required? Example JSON File { "id": 1, "name": "A green door",
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" }, "name": { "description": "Name item", "type": "string" } }, "required": ["id", "name"] } Is name required? Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] }

15 Can price be 0? Example JSON File { "id": 1, "name": "A green door",
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" }, "name": { "description": "Name item", "type": "string" }, "price": { "type": "number", "minimum": 0, "exclusiveMinimum": true } }, "required": ["id", "name", "price"] } Can price be 0? Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] }

16 Are all tags strings? Example JSON File { "id": 1,
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" }, "name": { "description": "Name item", "type": "string" }, "price": { "type": "number", "minimum": 0, "exclusiveMinimum": true }, "tags": { "type": "array", "items": { "minItems": 1, "uniqueItems": true } }, "required": ["id", "name", "price"] } Are all tags strings? Example JSON File { "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"] }

17 JSON Schema Are JSON Schema required for interpretation of JSON data?
JSON Schema File { "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" }, "name": { "description": "Name item", "type": "string" }, "price": { "type": "number", "minimum": 0, "exclusiveMinimum": true }, "tags": { "type": "array", "items": { "minItems": 1, "uniqueItems": true } }, "required": ["id", "name", "price"] } Are JSON Schema required for interpretation of JSON data? Yes No


Download ppt "JavaScript Object Notation"

Similar presentations


Ads by Google