JSON Tutorial
This JSON tutorial is useful for both beginners and experienced. In this JSON tutorial you will find all the useful examples related to JSON technologies.
Here we will see the definition and simple JSON examples in detail.
Here we will see the definition and simple JSON examples in detail.
What is JSON?
JavaScript object notation(JSON) is a light weight and data-interchange format. JSON objects are used for transferring a data between client and server.
JSON is language independent and it is easy for human to read and write.
JSON supports string, array, objects, number, value.
JSON uses JavaScript syntax but only in text format just like XML.
We can use JSON with other programming language e.g Java, Python, C#, C++, Perl, JavaScript, Ajax, JQuery, Ruby, etc.
JSON is text and we can convert any JavaScript object into JSON and send JSON to the server.
/* End */
finally, we have learned what is json , json array object example, json object example.
JSON supports string, array, objects, number, value.
JSON uses JavaScript syntax but only in text format just like XML.
We can use JSON with other programming language e.g Java, Python, C#, C++, Perl, JavaScript, Ajax, JQuery, Ruby, etc.
JSON is text and we can convert any JavaScript object into JSON and send JSON to the server.
History of JSON
JSON technology was invented by Douglas Crockford.
JSON is an alternative of an XML.
JSON is simple and easy to learn in comparison of XML.
JSON is simple and easy to learn in comparison of XML.
Syntax of JSON
- JSON allows to write a data in key and value pairs.
- JSON uses commas(":") to separate the data.
- JSON uses curly("{") braces to store objects.
- JSON uses square bracket( "[") to store the array.
Let's take simple look of JSON data
{"students":[
{"name":"anurag", "address":"f13"},
{"name":"anurag", "address":"g43"}
]}
JSON final must be save with .json extension.
JSON final must be save with .json extension.
JSON data types
Some data types are supported by JSON technology which are given below.
- String
- Array
- Boolean
- Value
- Object
- Number
- Whitespace
- null
We can create JSON example with the help of objects and arrays. Let's create examples of JSON one-by-one with objects and arrays.
(1) JSON Object Examples
This is the simple json object example. Here we will use curly braces and key & value pairs to represents json object where keys are string and values are json types and use comma to separate the data.
{
"student": {
"name" : "sunny",
"roll no" : 56,
"monitor" true
}
}
In the above example, "student" is an object and "name", "roll no" and monitor is a key with string, number and boolean type values for the keys.
In the above example, "student" is an object and "name", "roll no" and monitor is a key with string, number and boolean type values for the keys.
Each object can have different - different data such as text, number, boolean, etc.
JSON Object Example with String
To represents string values we use double quotes("").
{
"student": {
"name" : "karan", "address": "anand vihar"
}
}
JSON Object Example with Number
{
"student" : {
"Integer" : 56,
"fraction" : 1.23
}
}
JSON Object Example with boolean
{
"student" : {
"weak" : false,
"strong" : true
}
}
Nested JSON Object Example
{
"student" : {
"name" : "anu",
"rollo no" : 45,
"address" : {
"city" : "delhi",
"pincode" : "65"
}
}
(2) JSON Array Examples
JSON array can contains multiple and it can contains number, string, boolean, and objects in an JSON array.
We have to use square bracket [ to represents json array and for separation of values use comma.
We have to use square bracket [ to represents json array and for separation of values use comma.
JSON Array Example of String, Number, and Boolean
Json array string example:
["red", "blue", "black", "pink"]
Json array number example:
[2, 4, 1, 5]
Json array boolean example
[true, false]
JSON Array of Objects Example
{
"students" : [
{"name" : "raj", "email" : "raj@33", "roll no" : 10},
{"name" : "numan", "email" : "numan@66", "roll no" : 15},
{"name" : "ravi", "email" : "ravi@11", "roll no" : 125}
]
}
this is json array object example with 4 objects.
XML Example
XML representation of above example.
/* Start */
/* Start */
<students>
<student>
<name>raj</name>
<email>raj@33</email>
<roll no>10</roll no>
</student>
<student>
<name>naman</name>
<email>naman@66</email>
<roll no>15</roll no>
</student>
<student>
<name>ravi</name>
<email>ravi@11</email>
<roll no>125</roll no>
</student>
</students>
finally, we have learned what is json , json array object example, json object example.
Thanks for sharing this informative blog java training in chennai
ReplyDeletethanku very much for sharing such good article . visit also good json java tutorial
ReplyDeletethanks for sharing good article. visit one more json java tutorials
ReplyDeletethanks for sharing good article. visit one more https://www.javavogue.com
ReplyDeleteThanks for sharing such a great information.
ReplyDeleteJava Online Training
Java Online Training In Chennai
Java online Course in Chennai