JSON Introduction
JSON Introduction
Boolean
Values in Json can be true/false
Example: {"Sale": true}
JSON - Syntax
Data should be in key/value pairs {
"student":[
Data should be separated by commans
{
Curly braces should hold objects "id": "01",
"name": "Tom",
Square brackets hold arrays
"lastname": "Price"
},
{
"id": "02",
"name": "Nick",
"lastname": "Thameson"
}
]
}
JSON Object
JSON Object hold Key/Value pair. Each Key is represented as 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
{
"employee": {
"name": "sonoo",
"salary": 56000,
"married": true
}
}
JSON Nested Object Example
{
"FirstName": "Scott",
"LastName": "Jaiswal",
"age": "27",
"address": {
"streetAddress": "John St",
"city": "Newyork",
"state": "US",
"postalCode": "1011"
}
}
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, value must be separated by comma.
The [ (square bracket) represents JSON array.
Example:
{
"employees": ["John", "Anna", "Peter"]
}
{
"employees": [
{
"name": "Ram",
"email": "[email protected]",
"age": 23
JSON Array
},
{
JSON Example-1
{
"books":
[
{
"title": "Professional",
"authors": [
"Nicholas C. Zakas"
],
"edition": 3,
"year": 2011
},
{
"title": "Professional",
"authors": [
"Nicholas C. Zakas"
],
"edition": 2,
"year": 2009
},
{
"title": "Professional",
"authors": [
"Nicholas C. Zakas",
"Jeremy McPeak",
"Joe Fawcett"
],
"edition": 2,
"year": 2008
}
]
}
JSON Example-2
{ "store": {
"books":
[
{
"category": "reference",
"authors": "Nigel Rees",
"title": "Saying of the Century",
"price": 8.95
},
{
"category": "fiction",
"authors": "Evelyn Waugh",
"title": "Sword of Honor",
"price": 12.99
},
]
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
JSON Example-3
Represent Data in JSON
id 1212 JSON
isActive true
balance $1,742.36
age 34
name john
gender male
email [email protected]
phone +123456
address 123, xyz
tags
eiusmod
veniam
magna
friends
id 0
name Lula Cannon
id 1
name Rachel Snider
favoriteFriute banana
JSONPath
A JSONPath expression specifies a path to an element (or a set of
elements) in a JSON Structure.
Paths can use the dot notation:
$.store.book[0].title
or the bracket notation
$['store']['book'][0]['title']
$ represents the root object or array and can be omitted.
For example, $.foo.bar and foo.bar are the same,
and so are $[0].status and [0].status
JSONPath Expressions
JSONPath Expressions
JSONPath Reference
https://docs.oracle.com/cd/E60058_01/PDF/8.0.8.x/8.0.8.0.0/PMF_HTML/JsonPath_Expressio
ns.htm#:~:text=JsonPath%20expressions%20always%20refer%20to,is%20an%20object%20or
%20array.