0% found this document useful (0 votes)
5 views

JSON Introduction

JSON (JavaScript Object Notation) is a syntax for storing and exchanging data, designed for human-readable data interchange and supported by all major JavaScript frameworks. It consists of various data types including numbers, strings, booleans, objects, and arrays, and uses a straightforward syntax with key/value pairs. JSON can be manipulated easily and is recognized natively by JavaScript, making it a popular choice for data transmission and serialization.

Uploaded by

junokomeyasa
Copyright
© © All Rights Reserved
Available Formats
Download as KEY, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JSON Introduction

JSON (JavaScript Object Notation) is a syntax for storing and exchanging data, designed for human-readable data interchange and supported by all major JavaScript frameworks. It consists of various data types including numbers, strings, booleans, objects, and arrays, and uses a straightforward syntax with key/value pairs. JSON can be manipulated easily and is recognized natively by JavaScript, making it a popular choice for data transmission and serialization.

Uploaded by

junokomeyasa
Copyright
© © All Rights Reserved
Available Formats
Download as KEY, PDF, TXT or read online on Scribd
You are on page 1/ 21

JSON Introduction

JAVASCRIPT OBJECT ANNOTATION


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
Why use JSON?
Provide support for all browsers and Easy to read and write
Straightforward syntax, Easy to create and manipulate
Supported by all major JavaScript frameworks
Supported by most backend technologies
JSON is recognized natively by JavaScript
It allows you to transmit and serialize structured data using a network connection.
You can use it with modern programming languages.
JSON is text which can be converted to any object of JavaScript into JSON and send this JSON
to the server.
JSON Data Type
Number
String
Boolean
Null
Object
Array
Data Type
String
String in JSON must be written in Double Quotes "".
Example: {"name": "John"}
Numbers
Numbers in JSON must be an integer or floating point.
Examples: {"age": 3}
Object
Value in JSON can be objects.
Examples:
{
"employee": {"name": "John", "age": 30, "city": "New York"}
}
Data Type
Array
Value in JSON can be array.
Example:
{
"employees": ["John", "Anna", "Peter"]
}

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
},
{

of Object "name": "Saya",


"email": "[email protected]",
"age": 28
},
{
"name": "John",
"email": "[email protected]",
"age": 41
}
]
}
JSON Example
JAVA SCRIPT OBJECT ANNOTATION
{
"firstName": "John",
"lastName": "doe",
"age": 26,
"address": {
"streetAddress": "naist",
"city": "Nara",
"postalCode": "630-0192"
},
"phoneNumbers": [
{
"type": "iPhone",
"number": "0123-4567"
},
{
"type": "home",
"number": "0123-4567"
}
]
}

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

Writing JSON Code


JSON Path is query language for JSON
JSONPath Expression

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.

JSONPath Online Evaluator


https://jsonpath.com/

You might also like