1. What is JSON?
JSON is the abbreviation of JavaScript Object Notation. It is one of the simplest data interchange formats, independent of programming language and platform. Its lightweight text-based structure makes it easily readable. It is derived from JavaScript for presenting simple data in the form of key-value pairs.
It is often used for serialization and transmission of data between network connections. It is mostly used for data transmission between a web application and the server thereby making it a popular alternative to the XML format.
ย
2. How many data types are there in JSON?
There are six types of data types in JSON -
- Number
- String
- Boolean
- Array
- Object
- Null
ย
3. What is meant by JSON objects?
An object is defined as a set of key-value pairs. A JSON starts with a left brace โ{โ and ends with another right brace โ}โ. Every key is followed by a colon โ:โ and the key-value pairs are separated from each other by using a comma โ,โ. So, basically, the JSON object is a collection of keys along with their values arranged in a pre-specified JSON format.
ย
4. What is the difference between XML and JSON?
- XML requires XML parser to parse it. JSON is parsed with the help of JavaScript functions.
- XML is heavy and verbose. JSON is short and lightweight.
- File extension of XML data is .xml. File extension of JSON data is .json.
- XML is document based. JSON is data based.
- JSON is simple to read, write and understand. XML is less simple to read, write and understand.
- Array is supported by JSON. Array is not supported by XML.
- JSON stands for JavaScript Object Notation. XML stands for Extensible Markup Language.
ย
5. Which functions are used for encoding and decoding JSON in PHP?
For encoding, json_encode() function is used. This function takes PHP value like array as input and returns JSON representation of it. For decoding, json_decode() function is used. This function takes JSON string as input and returns associative array.
ย
6. What are the uses of JSON?
JSON is mainly used for data interchange between the two systems.
- JSON is prominently used for the transmission of serialized data over a network connection between two systems.
- APIs and web services use JSON to format and transfer data.
- JSON can be used in combination with most modern programming languages.
- JSON can be used with JavaScript applications such as browser plugins and websites.
- JSON can be used to read data from the web server and display data on the web pages.
ย
7. Mention what is JSONP?
JSONP stands for JSON with padding. It is a method used to bypass the cross-domain policies in web browsers. In other words, JSONP is the simple way to deal with browser restrictions when sending JSON responses from different domains from the client.
ย
8. Mention what is the difference between JSON and JSONP?
- JSON: JSON is a simple data format used for communication medium between different systems
- JSONP: It is a methodology for using that format with cross domain ajax requests while not being affected by same origin policy issue.
ย
9. What is the difference between JSON parse and JSON Stringy?
JSON.stringify() is to create a JSON string out of an object/array. They are the inverse of each other. JSON.stringify() serializes a JS object into a JSON string, whereas JSON.parse() will deserialize a JSON string into a JS object.
ย
10. What are the limitations of JSONP?
JSONP is used to bypass the same-origin policy of web browsers. It may seem like a perfect way to get around the restriction but it has its own set of limitations as well. They are:
- As all the JSONP calls are made by including a [removed] tag, the request made is confined only to the GET method.
- It cannot be used for POST or PUT requests.
- It can be used only for read-only services and APIs.
Comments
Leave a Comment
Your email address will not be published. Required fields are marked *