JSON
(JavaScript Object Notation)
& JSON Path
WWW.PAVANONLINETRAININGS.COM
What is JSON?
▪ JSON – Java Script Object Notation
▪ JSON is a syntax for storing and exchanging data.
▪ Basically It was designed for human-readable data interchange.
▪ JSON is text, written with Java Script Object Notation.
▪ It has been extended from the JavaScript scripting language
▪ The filename extension is .json
▪ JSON internet Media type is application/json
WWW.PAVANONLINETRAININGS.COM
JSON Data Types
▪ Number
▪ String
▪ Boolean
▪ Null
▪ Object
▪ Array
WWW.PAVANONLINETRAININGS.COM
Data Types
▪ String
▪ Strings in JSON must be written in double quotes.
▪ Example:
{ "name":"John" }
▪ Numbers
▪ Numbers in JSON must be an integer or a floating point.
▪ Example:
{ "age":30 }
▪ Object
▪ Values in JSON can be objects.
▪ Example:
{
"employee":{ "name":"John", "age":30, "city":"New York" }
}
WWW.PAVANONLINETRAININGS.COM
Data Types
▪ Array
▪ Values in JSON can be arrays.
▪ Example:
{
"employees":[ "John", "Anna", "Peter" ]
}
▪ Boolean
▪ Values in JSON can be true/false.
▪ Example:
{ "sale":true }
▪ Null
▪ Values in JSON can be null.
{ "middlename":null }
WWW.PAVANONLINETRAININGS.COM
JSON - Syntax
▪ Data should be in name/value pairs
▪ Data should be separated by commas
▪ Curly braces should hold objects
▪ Square brackets hold arrays
WWW.PAVANONLINETRAININGS.COM
JSON vs XML
WWW.PAVANONLINETRAININGS.COM
Examples
JSON Example XML Example
WWW.PAVANONLINETRAININGS.COM
JSON Object & JSON Array
WWW.PAVANONLINETRAININGS.COM
JSON Object
▪ JSON object holds key/value pair. Each key is represented as a string in JSON
and value can be of any type.
▪ The keys and values are separated by colon. Each key/value pair is separated
by comma.
▪ The curly brace { represents JSON object.
▪ Example:
WWW.PAVANONLINETRAININGS.COM
▪ JSON Object with Strings ▪ JSON Object with Numbers
{ {
"name": "Scott", "integer": 34,
"email": "[email protected]" "fraction": .2145,
"exponent": 6.61789e+0
} }
▪ JSON Object with Booleans ▪ JSON Nested Object
{ {
"firstName": "Scott",
"first": true,
"lastName": "Jaiswal",
"second": false "age": 27,
} "address" : {
"streetAddress": "Plot-6, Mohan Nagar",
"city": “Hyderabad",
"state": “TL",
"postalCode": “500090"
}
}
WWW.PAVANONLINETRAININGS.COM
JSON Array
▪ JSON array represents ordered list of values.
▪ JSON array can store multiple values. It can store string, number, boolean or
object in JSON array.
▪ In JSON array, values must be separated by comma.
▪ The [ (square bracket) represents JSON array.
WWW.PAVANONLINETRAININGS.COM
JSON Array of Strings
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
JSON Array of Numbers
[12, 34, 56, 43, 95]
JSON Array of Booleans
[true, true, false, false, true]
JSON Array of Objects
{"employees":[
{"name":"Ram", "email":"
[email protected]", "age":23},
{"name":"Shyam", "email":"
[email protected]", "age":28},
{"name":"John", "email":"
[email protected]", "age":33},
{"name":"Bob", "email":"
[email protected]", "age":41}
]}
WWW.PAVANONLINETRAININGS.COM
WWW.PAVANONLINETRAININGS.COM
Capture & Validate JSON Path
https://jsonpathfinder.com/
https://jsonpath.com/
WWW.PAVANONLINETRAININGS.COM