5. JSON
5. JSON
Like XML, JSON also is a 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.
The filename extension of JSON is “.json“
JAVA
XML JSON
<employee> {
<emp-id>123</emp-id> "EmpID":123,
<emp-name>Deepak</emp-name> "EmpName":“Deepak",
<emp-salary>200.12</emp-salary> "EmpSal":200.12
</employee> }
JSON Syntax
JSON Data
A name/value pair consists of a field name (Should be in double quotes) followed by a colon-
followed by a value
JSON value
1. String
2. Number
3. Boolean
4. NULL
6. An Array
7. An Object Array
In JSON,
JSON Array
Array values must be a valid JSON data type-(String, Number, Object, Array, Boolean or null)
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 Developers have to write JavaScript code to serialize/
deserialization/serialization JavaScript. de-serialize from XML.
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