Json & XML: Web Technology: 2021
Json & XML: Web Technology: 2021
▪ Syntax
▪ Data types
▪ Schema
❑ eXtensible Markup Language
▪ Structure & Syntax
▪ XML and JSON
Introduction
Type Description
Syntax
MP.WEBTECH.IT.KMITL
Example
{
"books": [
{ "language":"Java" , "edition":"second" }, 0
{ "language":"C++" , "lastName":"fifth" }, 1
{ "language":"C" , "lastName":"third" } 2
]
}
JSON : array
Object
Array
Object
JSON : array of object
Syntax
let object-name = { name : value, .......}
Example
let obj = {“price": 500, “product”: ”Shampoo” }
JSON : string
{
"name": "John Doe",
"age": 30,
"married": true,
"siblings": ["John", "Mary", "Pat"]
}
Syntax
let json-object-name = { string : "string value", .......}
Example
let obj = {"name": "Amit"}
JSON : number
Type Description
[
Company Contact Country {
Alfreds Futterkiste Maria Anders Germany "company": "Alfreds Futterkiste",
"contact": "Maria Anders",
Centro Francisco
Mexico "country": "Germany"
commercial Chang
},
Ernst Handel Roland Mendel Austria {
"company": "Centro Commercial",
"contact": "Francisco Chang",
"country": "Mexico"
Company Contact Country },
Alfreds Futterkiste Maria Anders Germany {
"company": "Ernst Handel",
{ "contact": "Roland Mendel",
"company": "Alfreds Futterkiste", "country": "Austria"
"contact": "Maria Anders", }
"country": "Germany" ]
}
JSON Schema
{ JSON
"firstName": "John",
"lastName": "Doe",
"age": 21
}
{ JSON Schema
"$id": "https://example.com/person.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name."
},
JSON Schema
JSON string.
<script>
let s = '{"firstname" : "Sammy", "lastname" : "Shark", "location" :
"Ocean"}’; String
5
MP.WEBTECH.IT.KMITL
Attributes
XML Declaration
<element> … </element>
root element.
<root>
<x>...</x>
<y>...</y>
</root>
formed document.
▪ XML documents must have a root element
▪ XML elements must have a closing tag
▪ XML tags are case sensitive
▪ XML elements must be properly nested
▪ XML attribute values must be quoted
XML and JSON
https://https://www.json.org
❑ What is JSON?
https://www.w3schools.com/js/js_json_intro.asp
❑ JSON - Introduction
https://www.w3schools.com/js/js_json_intro.asp
❑ JSON Tutorial
https://www.tutorialspoint.com/json/index.htm
❑ JavaScript Tutorial
https://www.w3schools.com/js/default.asp
❑ XML DOM Tutorial
https://www.w3schools.com/xml/dom_intro.asp
❑ XML DOM Tutorial
https://www.tutorialspoint.com/dom/