Open In App

JSON Interview Questions

Last Updated : 30 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

JSON or JavaScript Object Notation is a format that is independent of any language and used for data transmission between the server and the web app. It is a lightweight data-interchange format that mainly uses JavaScript syntax but always formats in text format only.

JSON Interview Questions

1. What is JSON?

JSON stands for JavaScript Object Notation but it does not use JavaScript to perform operations, it just uses the JavaScript syntax. It is a light-weighted and language-independent format mainly used to transmit the data between the server and the web app.

2. Explain the structure and format of JSON.

The JSON format follows the structure of the JavaScript object. It contains the key-value pairs in the form of strings that can be transmitted from server to web app and vice-versa. The values stored in JSON can be retrieved in the same way as the values of JavaScript object are retrieved.

{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}

3. Who created JSON?

Douglas Crockford was the first man who introduced and created the JSON format first in 2000.

4. What is the extension for the JSON files?

The JSON files can be created and stored using the .json extension. You can add the data in the form of JSON format using the key-value pairs in the form of strings.

5. What is the reason for using JSON?

JSON is a light weighted format that is used to transfer the data on the network. The main reason for using JSON is that it provides a very simple and easy way to communicate between the server and the web app by data transmission. It is used as an alternative for the XML format.

6. What are the features of JSON?

There are different features of JSON as listed below:

  • It is a light weight format that helps to optimize the performance of the web app.
  • It is independent of different programming languages.
  • It has a vast support from different programming languages.
  • The JSON format is very easy to understand.
  • It can represent the complex data structures.

7. List different data types supported by JSON.

JSON has a support for the following data-types:

  • Number
  • Boolean
  • String
  • Array
  • Object
  • null

8. How to create a JSON array?

A JSON array is just like the arrays in the other programming languages that contains a collection of multiple items of different data-types. It can contain value of any data-type supported by JSON.

["value1", 12, true, null]

9. Is it possible to create function in JSON?

No, as we know JSON is just a data format and it is used to transfer data on the network. Therefore, we can not write any kind of executable code inside it.

10. How to retrieve the data stored in JSON object?

You can retrieve or access the values stored in an JSON object in the same way as we access them in JavaScript. The below methods can be used to access the values of JSON object.

  • Using dot notation
  • Using square brackets

11. Explain the process of accessing JSON object values using dot notation.

You can follow the below syntax to retrieve values of JSON object using dot notation.

const JSONObj = {
"name": "GFG",
"est": "2009",
"workForce": "200+"
}
console.log(JSONObj.name)
console.log(JSONObj.est)
console.log(JSONObj.workForce)

12. Explain the process of accessing JSON object values using square brackets.

You can follow the below syntax to retrieve values of JSON object using square brackets.

const JSONObj = '{
"name": "GFG",
"est": "2009",
"workForce": "200+"
}'
console.log(JSONObj["name"])
console.log(JSONObj["est"])
console.log(JSONObj["workForce"])

13. Explain JSONP and how it is different from JSON?

JSONP stands for JSON with Padding. It is a method for sending the JSON data with padding to avoid cross domain restrictions. JSONP is different from JSON, because it allows the cross-origin requests.

14. List different browsers that support JSON.

JSON is supported by all the modern browsers. As we know, JSON follows the JavaScript syntax, hence every browser has built-in support for it. The below browsers support JSON:

  • Google Chrome
  • Mozilla Firefox
  • Safari
  • Microsoft Edge
  • Opera, etc.

15. Explain the use of JSON.parse() method in JSON.

The JSON.parse() method is used to parse the JSON data into JavaScript and converts the JSON string into a JavaScript object.

JSON.parse(JSONString, function)

16. What is the JSON.stringify() method used for?

The JSON.stringify() method is used to convert the JavaScript object into a JSON string format.

JSON.stringify(JSONString, function, space)

17. Explain JSON schema.

JSON schema is a content specification language defined to validate the structure and the format of JSON data or string. It defines the basic structure, format and important constraints of JSON data.

18. How to write JSON in an HTML document?

You can write or include the JSON data inside and HTML document using a <script> tag with type attribute by passing a value as application/json to it.

<script type="application/json">
// JSON data
</script>

19. What are the methods used to encode and decode JSON in PHP?

We can use the below methods to encode and decode JSON in PHP:

  • json_encode(): This method is used to encode JSON in PHP. It takes the data in PHP array format and converts it into JSON data.
  • json_decode(): It is used to decode JSON in PHP. It takes a JSON string as input and returns corres[ponding PHP array.

20. What is the MIME type for JSON?

The MIME type for JSON is application/json. You can pass this type as an value to the type attribute inside the script tag to include JSON into your HTML document.

21. What are the benefits of using JSON?

The below list contains some benefits of using JSON:

  • It is easy to implement and understand.
  • It can be used with any language due to its language independency.
  • It’s a very lightweight data interchange format on the network.
  • It’s an alternative of XML.

22. Explain disadvantages of using JSON.

There are some disadvantages of using JSON:

  • It does not have any Document Type Definition.
  • It is not good for large scale data products.
  • There’s no type definition of it.
  • It is not safe to use with untrusted services and browsers as it does not have a solid security mechanism.
  • It can output a complex data in case of large data set which may be difficult to understand.

23. What are the applications of JSON?

JSON can be used in different situations:

  • It serializes and transmits the structured data over a network connection.
  • There are multiple web services and APIs available on the internet that returns the data in JSON format when the data is fetched from them using JavaScript or any other language.
  • It transfers the data between the servers and web applications.

24. List some of the popular libraries for working with JSON in JavaScript.

Below are some of the popular libraries for working with JSON in JavaScript:

25. Differentiate between JSON and XML.

JSON and XML are the formats used to transfer data over the network. But there are some differences between them as listed in the below table:

JSON

XML

It stands for JavaScript Object Notation.

It stands for Extensible Markup Language.

It doesn’t use any tag.

It uses end tag.

It allows to create arrays.

It does not have arrays.

JSON is simple and easy to read as well as write.

XML is a little complex as compare to JSON.

It does not have a robust and strong security mechanism.

It is much secure than JSON.

26. What are the similarities between JSON and XML?

There are some similarities between JSON and XML as listed below:

  • Both of them are used to transmit data to the network connection.
  • Both are simple and human-readable.
  • They are language independent.
  • Both of them supports hierarchical and nested structure i.e. values within values or objects with object.
  • They can be fetched by sending requests to the servers.

27. What is Serialization and Deserialization in JSON?

  • Serialization: It is the term refer to the process of transforming and object to the string.
  • Deserialization: It is the process of converting a string back into an object.

28. How to handle JSON parsing errors in JavaScript?

The JSON parsing errors can be handled using the try/catch block with the parsing statements in JavaScript.

29. Is it possible to create duplicate keys in an JSON object?

No, JSON does not allow to create duplicate keys in an object. If there’s a duplicate key created in some scenario, then the last occurrence of that key will replace the previous occurrence.

30. Explain JSON web token and its implementation.

JSON web token or JWT is a self-contained and compact way to transmit the data securely between server and web app in JSON object format. It consist of three parts as the header, the payload, and the signature. All the parts of JWT are encode in base64 format which are concatenated to form a JWT.

31. How to transmit JSON data securely over the internet?

The JSON data can be securely transmitted over the internet using the HTTPS (Hyper Text Transfer Protocol Secure) protocol. It encrypts the data during its transmission over the internet.

32. What is JSON-LD and how it is different from JSON?

JSON-LD stands for JSON for Linking Data. It is a lightweight Linked Data format that is designed to integrate with the JSON based APIs that are already existing on he internet. It is different from regular JSON as it involves the additional context and semantics for the better data interoperability.

33. What is the purpose of toJSON() method in JSON?

The toJSON() method in JSON is used to convert the date returned by the Date constructor in the string format.

dateObj.toJSON();

34. What are JSON formatter and Validator?

The JSON formatter and Validators are the tools used to format and validate the JSON data. These tools convert the JSON data into a human-readable format by ensuring its readability, correctness, and adherence to JSON syntax.

35. What are the alternatives of JSON?

There are some alternatives available for JSON as listed below:

  • XML (Extensible Markup Language)
  • Protocol Buffers (protobuf)
  • YAML
  • MessagePack
  • BSON (Binary JSON)
  • CBOR (Concise Binary Object Representation)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads