Capter-8 JSON
Capter-8 JSON
Capter-8 JSON
Like XML, JSON also is a "Language” & Platform Independent Language" which helps to store
and transport data
However, compared to XML, it’s a lightweight, easy for applications to parse and generate by
avoiding complicated parsing and translations
JSON, as the name implies, which consists of data similar to "Object Notation of
JavaScript".It's an extension of JavaScript
Hence if we receive data from a server in JSON format, we can directly use it like any other
JavaScript object
JAVA
00.12";
XML
<employee>
<emp-id>123</emp-id>
<emp-name>Deepak</emp-name>
<emp-salary>200.12</emp-salary>
</employee
JSON
"EmpID":123,
"EmpNM":“Deepak",
"EmpSal":200.12
JSON Syntax
JSON Data
Ex:
"employee-name“ : “Deepak”
JSON value
1.String
2.Number
3.Boolean
4.NULL
In JSON,
EG:
JSON Object
EG :
"employee":{
"name":"Praveen D",
"age":33,
"isEmployed":true,
"girlFriend":null
JSON Array
Example 1:-
Example 2:-
"name":“Deepak",
"age":33,“
}
JSON /XML
JSON XML
JSON data has a data type , light weight XML data is type less
JSON types: string, number, array, Boolean,
null ,Object All XML data should be string
Data is readily accessible as JSON objects XML data needs to be parsed.
JSON is supported by most browsers. Cross-browser XML parsing can be tricky
Retrieving value is easy Retrieving value is difficult
A fully automated way of DE Developers have to write JavaScript code to serialize/
serialization/serialization JavaScript. de-serialize from XML
The object has to be express by conventions - mostly
Native support for object. missed use of attributes and elements.
It supports only UTF-8 encoding. It supports various encoding.
It doesn't support comments. It supports comments.
XML documents are relatively more difficult to read
JSON files are easy to read as compared to XML. and interpret.
It is less secured. It is more secure than JSON.
JSON Parser
JAX-RS, JACSON, JERSEY is a Java API helps us to convert Java Object to JSON& vice-versa
Or
OR
Answer
EG :
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-lgpl</artifactId>
<version>1.9.13</version>
</dependency>
package pac;
OUTPUT :
Or
OR