JavaScript Object Notation Plain text file format Although originally derived from the JavaScript scripting language JSON is a languageindependent data format Whitespace outside of strings isnt meaningful ID: 776188
Download Presentation The PPT/PDF document " JSON JavaScript Object Notation" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
JSON
JavaScript Object Notation
Slide2JavaScript 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)
Slide3JSON 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"
Slide4JSON Strings
Which of these are JSON strings?Josh"Josh\n""\_(^^)_/"""
Slide5JSON 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
Slide6JSON array
array: an ordered list of zero or more values, each of which may be of any type.
[][4, "Josh", true][[], null]
Slide7JSON object
object: an unordered collection of name/value pairs where the names (also called keys) are strings.
{"name":"Josh", "age":17, "section":[1,2]}
Slide8JSON values (null and boolean)
null: empty value
nullboolean: either of the values truefalse
Slide9Example JSON File
{
"name":"josh",
"pets": [{
"name": "zoe",
"age":7,
"birthday":null,
"species":"dog",
"commands":["fetch", "shake", "come"]
}],
"employed":true
}
Slide10JSON 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: http://json-schema.org/
Slide11JSON Schema
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?
Slide12Example JSON File{ "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"]}
JSON Schema File{ "title": "Product", "description": "Product from catalog", "type": "object"}
What is the data?
Slide13Example JSON File{ "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"]}
JSON Schema File{ "title": "Product", "description": "Product from catalog", "type": "object", "properties": { "id": { "description": "unique id", "type": "integer" } }, "required": ["id"]}
What is
id
?
Slide14Example JSON File{ "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"]}
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?
Slide15Example JSON File{ "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"]}
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?
Slide16Example JSON File{ "id": 1, "name": "A green door", "price": 12.50, "tags": ["home", "green"]}
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": { "type": "string" }, "minItems": 1, "uniqueItems": true } }, "required": ["id", "name", "price"]}
Are all
tags
strings?
Slide17JSON Schema
Are JSON Schema required for interpretation of JSON data? YesNo
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": {
"type": "string" },
"minItems": 1,
"uniqueItems": true } },
"required": ["id", "name", "price"]
}