JSON Java Script Object Notation Java Script Object
JSON Java. Script Object Notation
Java. Script Object Notation Plain text file format Although originally derived from the Java. Script 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)
JSON string: a sequence of zero or more Unicode characters. Strings are delimited with double -quotation marks and support a backslash escaping syntax. • "Hin. Everyone"
JSON Strings Which of these are JSON strings? Josh "Joshn" "_(^^)_/" ""
JSON number: a signed decimal number that may contain a fractional part and may use exponential E notation. • 4 • 12. 5 • 6. 022 e 23 • -5. 6
JSON array: an ordered list of zero or more values, each of which may be of any type. • [] • [4, "Josh", true] • [[], null]
JSON object: an unordered collection of name/value pairs where the names (also called keys) are strings. • {"name": "Josh", "age": 17, "section": [1, 2]}
JSON values (null and boolean) null: empty value • null boolean: either of the values • true • false
Example JSON File { "name": "josh", "pets": [{ "name": "zoe", "age": 7, "birthday": null, "species": "dog", "commands": ["fetch", "shake", "come"] }], "employed": true }
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: http: //jsonschema. org/
JSON Schema Questions the schema should answer: Example JSON File { "id": 1, "name": "A green "price": 12. 50, "tags": ["home", } 1. What is the data? door", "green"] 2. What is id? 3. Is name required? 4. Can price be 0? 5. Are all tags strings?
What is the data? Example 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 id? Example 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"] }
Is name required? Example 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"] }
Can price be 0? Example 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, "exclusive. Minimum": true } }, "required": ["id", "name", "price"] }
Are all tags strings? Example 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, "exclusive. Minimum": true }, "tags": { "type": "array", "items": { "type": "string" }, "min. Items": 1, "unique. Items": true } }, "required": ["id", "name", "price"]
JSON Schema Are JSON Schema required for interpretation of JSON data? Yes No 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, "exclusive. Minimum": true }, "tags": { "type": "array", "items": { "type": "string" }, "min. Items": 1, "unique. Items": true } }, "required": ["id", "name", "price"]
- Slides: 17