20+ Best JSON Interview Questions & Answers To Get Hired With

We've compiled the absolute best JSON interview questions and answers to help you in your upcoming technical interviews. JSON is commonly covered in technical interviews as it relates to common web development practices for modern applications. JSON objects are an easy way to share data between two applications or between models. It is also considered a fairly lightweight way to pass data. Lastly, the increased usage of JavaScript-based applications have made JSON a more popular file type for passing and parsing data.

Why is JSON covered in technical interviews

JSON is covered in technical interviews because it is fairly standard practice for sending data between backend and front-end applications and frameworks. For example, if you are a backend engineer and wanting to work with a front-end engineer, you will need to create the logic that serves up the front-end JSON objects. This is known as an API-driven development framework and in recent years (2013 — now) has become far more popular than what used to be standardized (sending all available data to the front-end controller in order to be parsed by that controller). If you are going to be working with teams, knowing JSON is going to be essential. Whether you are on the front-end or backend team, this is something you will need to know.

JSON Interview Questions & Answers

Let's begin with our interview questions and answers related to JSON. As always, use this as a guide to help you prepare for upcoming interviews. We recommend that you test with a friend or someone close to you to anticipate questions that might not be covered in this guide.

1. What is JSON used for primarily in modern applications?

JSON is used to represent a piece of data as a series of key: value pairs. It is commonly used as a format with which data is sent between applications, often over HTTP requests or simply between functions that exist within one application.

2. In making an AJAX call between a front end application and a backend service, name two ways JSON is likely used?

First, requests which are sent from the User Interface to the Backend application are likely to use JSON formatting.

Secondly, the Backend application will respond carrying its own JSON payload which can be displayed, modified, or otherwise used for meaningful processes within the Frontend application.

3. Write a JSON object that represents a person, with properties “name”, “profession”, “education”, and “dob”. The values for each field can be arbitrary.

{
  “name”: “Joe”,
  “profression”: “Doctor”,
  “education”: “M.D.”,
  “dob”: “09/09/1976”
}

4. Imagine in a Javascript application, when calling the function:

JSON.parse(jsonString);

you receive the following error:
[EXPLICIT] SyntaxError: Unexpected token } in JSON at position 107

What can you infer from this error about what the problem is in your application?

This error occurs because the variable `jsonString` is not a valid JSON string. It has an unexpected `}` character which is making it invalid. You can troubleshoot such an error by logging the variable’s value which you are trying to parse, and pasting it into a JSON validator online. Fixing the string’s syntax will eliminate this error.

5. Assume you are asked to process a JSON string within a Java application, take some data from the JSON, and set the values into variables. Is this possible? What about for a PHP application, C++?

For all of these languages this task is possible. JSON is a language-agnostic way to communicate data, similar to XML. This is possible because JSON is text-based, it can be sent between and within applications as a string.

6. How would you identify that a file is a JSON file?

The first way to determine if a file is a JSON file is by checking its file extension, which is .json in the case that the file is a JSON file.

7. Assume you want to leave notes about some JSON file in your codebase for another developer, what are your options? Can you leave comments directly in your JSON file?

Unfortunately, comments are not supported in the JSON format. One option to provide human-readable information or annotations about a JSON file, is to put a README.md file in the directory where your JSON file(s) are stored. In this README.md, you can put formatted information describing the purpose of the JSON files you are storing, if necessary.

8. Describe JSON Schema and an example of what a JSON Schema may be used for.

A JSON Schema is a way of describing the contents of a JSON object. Within a JSON schema, you can define which properties you expect a JSON object to possess. You can make more specific requirements and descriptions for a JSON object, for example, if a property is required, the type of a property, or the minLength or maxLength of a property.

One useful way to leverage JSON Schema is using a JSON Schema to define a set of validation rules for JSON objects before persisting them to a database.

9. Is JSON a programming language?

JSON is not a programming language. It is a data-format language. It does have a close relationship with the Javascript programming language because its formatting is the same as Javascript’s Object Literals.

10. What is one advantage in using JSON to transmit data instead of XML?

JSON is a lighter-weight data format, allowing you to express the same data structure with fewer characters.

11. In a Javascript application, why would a developer often opt to use JSON as a data-format language than XML.

Because Javascript’s Object Literals are nearly identical to JSON objects, our application will have native support for doing things like parsing and manipulating our data. A javascript application will have less native support for reading or manipulating XML data, possibly requiring the use of external libraries.

12. In the Javascript programming language, what is the difference between JSON.parse() and JSON.stringify()?

JSON.parse() and JSON.stringify() can most simply be thought of as opposites of one another.

Given a Javascript Object Literal, JSON.stringify() will return a string containing all of the characters in the JSON data-structure.

Oppositely, given a string with the characters of a JSON data-structure, JSON.parse() will return a Javascript Object Literal.

13. What is a polyfill, and why would it ever need to be used in the context of JSON?

A polyfill is a piece of code, usually referring to javascript code, which can be added to an application to provide support for functionality which does not exist in a given browser. Meaning, for example, since Internet Explorer 8 does not support the same functionality as Chrome, we could use a polyfill to support Chrome features in an application running on IE 8.

In the context of JSON, a polyfill would be important if you are writing a Javascript application which needs to run and process JSON data in Internet Explorer 6.

14. Which are the data types supported within a JSON Object?

A JSON Object supports the types: string, number, object, array, boolean, and null.

15. Assume we have some nested data structure represented by a JSON object, and we want to store that data in our application’s database. What are some considerations we should make about how to store the data.

One important consideration is if we are using a NoSQL database like mongodb or elasticsearch, or a relational database like mySQL or PostgreSQL. If we are using a NoSQL database, we can store JSON objects, even those with a complicated nested structure, as documents directly within our NoSQL database. We will then be able to send queries to the database to find our object, even based upon properties nested within the JSON object we stored.

A relational database, on the other hand, may not be the best place to directly insert a JSON object. It may be possible to store JSON within a database table’s column, and newer versions of databases like PostgreSQL offer some functionality surrounding querying upon stored JSON; however, this is often not an ideal solution. In a relational database, we might consider breaking the nested JSON structure into its nested entities and storing those entities within their own tables. This way, we can keep the data queryable via JOIN statements.

16. What is the mime-type of JSON data? When might this type become important for you as a developer?

The mime-type of JSON data is `application/json`. As a developer, you will often run into APIs on the web which requires you to declare the mime-type of data you are sending to the server. You may also be working with a library for making HTTP requests, which requires you to declare the mime-type of the data you expect to receive from a GET or POST response.

17. What is JSONP and when is it used?

JSONP stands for JSON with Padding. It is not a data-format language, but instead, it is a method used to get around a web-browser security feature surrounding Cross-Origin-Resource-Sharing. Modern web browsers prevent web servers on different domains from sending JSON data to one another via HTTP, unless the communication between the two domains is configured so that it is explicitly allowed.

For example, if I am building a UI application at my-ui.com, and I want to make an AJAX request to fetch JSON data from my-data-server.com, my browser will prevent this AJAX request from succeeding! I then have two options: 1) configure my-data-server.com to accept requests from my-ui.com, or 2) use JSONP to side-step the Cross-Origin-Resource-Sharing restriction.

JSONP requests are restricted to transmitting data through GET requests. Attempting to use the HTTP methods PUT, POST, PATCH, or DELETE with JSONP will fail.

18. Say you are writing a simple application which allows users to create to-do lists. Could you use .json files as a data-storage mechanisms for to-dos? What would be some advantages and limitations?

Yes. .json files can be used to persist data in an application. The advantage is that this solution is extremely simple. .json files are stored in static files directly in your application’s file-system, and no database software like mongodb or PostgreSQL would need to be installed to store and manage the data.

There are some disadvantages; however, as well. There is no native query language with which you’ll be able to query static .json files. Either a library or custom application code will be required to read/write from the .json files. This complexity could grow unmanageable for any application which needs more than a very small amount of simple, non-relational data storage.

19. What do square brackets `[` or `]` indicate in a JSON data structure?

Square brackets indicate that the given value is an array. `[` indicates the start of the array, and `]` indicates the array’s end.

20. What are the uses for tools like Terraform or Cloudformation, how do these tools use JSON in the context of Dev Ops?

Cloudformation and Terraform are tools that support “Infrastructure as code”. They allow a Dev Ops engineer to describe a “Stack” (a collection of cloud-infrastructure resources) required to support a web application through a service like AWS or Google Cloud Platform.

By following a specific JSON data structure, a Dev Ops engineer can, for example, describe a cloud-infrastructure environment containing a load balancer, 2 web servers, a database, and a firewall for security. By running this JSON file through a tool like Cloudformation, all of the infrastructures can be spun-up and configured as is defined in the JSON file. This greatly reduces the risk and increases the ease and consistency of managing cloud infrastructure.

21. Write a function that validates a JSON object. It should return true if given a valid JSON object, and false if not.

function isValidJSON(json) {
  try {
   JSON.parse(json);
   return true;
  } catch ()
   return false;
  }
}

22. In Javascript, how do you delete the `telephoneNumber` element from a JSON object stored in a variable called `person`?

delete person[“telephoneNumber”];

author: patrick algrim
About the author

Patrick Algrim is an experienced executive who has spent a number of years in Silicon Valley hiring and coaching some of the world’s most valuable technology teams.

Want higher salary?

Our comprehensive free guide on increasing your salary through new or existing employment has finally dropped. Get it here.

     

    Share

    Help us by spreading the word