JSON Interview Questions for 2 years experienced JavaScript developer

JSON interview questions for developers with 2 years of experience typically focus on understanding the basics and applying JSON in real-world scenarios. Topics often include parsing and stringifying JSON data, handling nested structures, working with APIs to fetch and send JSON data, and troubleshooting common JSON-related errors. Developers are also expected to demonstrate knowledge of JSON’s syntax, data types, and its role in modern web development, particularly in client-server communication. Familiarity with JSON’s integration in JavaScript and its use in frameworks or libraries is usually emphasized.

Here are some JSON questions you can consider asking your candidate.


1. What is JSON?

JSON is a text-based data-interchange format used to store and exchange data. It is often used with JavaScript but is language-independent, supported by almost every modern programming language.


JSON is popular because of its lightweight structure, readability, and ease of use. It is faster to parse and less verbose than XML, making it an ideal choice for APIs.


3. How does JSON compare to XML?

JSON is simpler and easier to read than XML. While XML uses tags, JSON uses key-value pairs. JSON is lightweight, whereas XML tends to be more verbose.


4. What are the basic data types supported in JSON?

JSON supports six basic data types:

  • Strings
  • Numbers
  • Objects
  • Arrays
  • Booleans
  • Null

5. How is data structured in JSON?

JSON organizes data as key-value pairs within objects {} and arrays []. For example:

{
    "name": "Vikas",
    "age": 30,
    "skills": ["JavaScript", "ReactJS","VueJS"]
}

6. What are JSON objects?

JSON objects are unordered sets of key-value pairs enclosed in curly braces {}. Each key is a string, and the value can be any supported JSON type.


7. What are JSON arrays?

JSON arrays are ordered collections of values enclosed in square brackets []. Values can be of any JSON-supported data type.

{
  "fruits": ["Apple", "Banana", "Cherry"]
}

8. Can JSON keys have duplicate names?

No, JSON does not allow duplicate keys within the same object. If duplicate keys are present, behavior depends on the parser.


9. What is JSONP, and how does it work?

JSONP (JSON with Padding) is a technique used to bypass the same-origin policy in web browsers. It allows data fetching from a server on a different domain. JSONP wraps the JSON response in a callback function.

Example:

Client request:


Server response:

myCallback({
  "name": "Vikas",
  "age": 42
});

10. What are the limitations of JSONP?

  • Only supports HTTP GET requests.
  • Limited to older browsers (modern browsers support CORS).
  • Vulnerable to security issues like XSS attacks.

11. What is a JSON Web Token (JWT)?

A JSON Web Token (JWT) is a compact, URL-safe token format used to securely transmit information between parties. It is often used for authentication and authorization.


12. How do you handle nested objects in JSON?

JSON allows nesting objects inside other objects or arrays. For example:

{
  "person": {
    "name": "Vikas",
    "address": {
      "city": "Surat",
      "zip": "395001"
    }
  }
}

13. How is JSON parsed in JavaScript?

JavaScript provides JSON.parse() to parse JSON strings into objects and JSON.stringify() to convert objects to JSON strings.

const jsonString = '{"name": "Vikas"}';
const obj = JSON.parse(jsonString);
console.log(obj.name); // Output: Vikas

14. What are JSON Patch and JSON Merge Patch?

  • JSON Patch: A format for describing changes to JSON documents. It uses an array of operations like add, remove, and replace.

    Example:

    [
      { "op": "replace", "path": "/name", "value": "Vikas" }
    ]
    
  • JSON Merge Patch: A simpler way to update JSON documents by merging new fields with the existing document.

    Example:

    { "name": "Vikas" }
    

16. How is a JWT structured?

A JWT consists of three parts:

  1. Header: Metadata, like the algorithm used.
  2. Payload: Claims (data to be transmitted).
  3. Signature: A cryptographic hash to verify the integrity.

Example:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImpvaG4iLCJyb2xlIjoiYWRtaW4ifQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

17. Can JSON handle date and time?

JSON does not have a native date/time format, but dates are often represented as ISO 8601 strings.

{
  "date": "2024-12-21T00:00:00Z"
}

18. What are JSON schemas?

JSON Schema is a vocabulary for validating JSON documents. It describes the structure and constraints of JSON data.


19. How do you validate a JSON structure?

You can validate JSON with JSON Schema, which defines rules for fields, types, and required properties.


20. What is a JSON Web Token (JWT)?

JWT is a compact, URL-safe token format used for securely transmitting information between parties as a JSON object.


21. How do APIs use JSON?

APIs often use JSON to format data sent between clients and servers because it is lightweight and easy to parse.


22. Can JSON contain functions?

No, JSON does not support functions. It is purely a data format.


23. What is JSON-LD, and why is it used?

JSON-LD (JSON for Linked Data) is a lightweight format for embedding structured data in web pages. It is widely used for SEO and schema markup.

Example:

{
  "@context": "https://schema.org",
  "@type": "Person",
  "name": "Vikas Bhagwagar",
  "jobTitle": "Remote Software Engineer",
  "url": "https://vikaskbh.com"
}

24. How can you pretty-print JSON?

In JavaScript, you can use JSON.stringify() with indentation:

console.log(JSON.stringify(obj, null, 2));

25. What is JSON Streaming?

JSON streaming is a technique to process large JSON data incrementally, reducing memory usage. Tools like ijson in Python or Jackson in Java are often used.


26. How do you use JSON for data binding in frontend frameworks like React?

In React, JSON is often fetched from APIs and used to bind data to components. Example:

const [data, setData] = useState([]);

useEffect(() => {
  fetch("https://api.example.com/data")
    .then((response) => response.json())
    .then((json) => setData(json));
}, []);

27. How do you handle special characters in JSON strings?

Special characters are escaped using a backslash. For example:

{
  "text": "He said, \"Hello!\""
}

28. Can JSON handle binary data?

JSON does not directly handle binary data but can encode it as a Base64 string.


29. What is a JSONP request?

JSONP (JSON with Padding) is a method to fetch data from a server in a different domain, now largely replaced by CORS.


30. How do you secure JSON data?

To secure JSON data, ensure proper validation, sanitation, and transport over HTTPS.


31. What are some common JSON parsing errors?

  • Unexpected token
  • Invalid character
  • Trailing commas
  • Missing double quotes

32. How do you merge two JSON objects?

You can use the spread operator in JavaScript:

const merged = { ...obj1, ...obj2 };

33. How do you convert JSON to a Map in JavaScript?

Use Object.entries() and Map:

const map = new Map(Object.entries(jsonObject));

34. What is JSONPath?

JSONPath is a query language for JSON, similar to XPath for XML.


35. Can you use JSON in Python?

Yes, Python has a built-in json module.


36. How do you load a JSON file in Python?

Use json.load():

import json
with open('data.json') as file:
    data = json.load(file)

37. What is JSON.parse() in JavaScript?

JSON.parse() converts a JSON string to a JavaScript object.


38. Can you store JSON in a database?

Yes, many databases like MongoDB and PostgreSQL support JSON storage.


39. What is the difference between JSON and JavaScript objects?

JSON is a string representation of data, whereas JavaScript objects are in-memory structures.


40. How do you handle large JSON files?

You can use streaming parsers like Jackson in Java or libraries like ijson in Python.


41. What is JSON Hijacking?

JSON Hijacking is a type of CSRF attack targeting JSON data exposed in GET requests.


42. How do you handle JSON errors in APIs?

APIs often return structured error responses:

{
  "error": "Invalid request",
  "code": 400
}

43. How do you work with nested JSON in Python?

Access nested keys using standard dictionary syntax.


44. What is the MIME type for JSON?

The MIME type for JSON is application/json.


Popular libraries include axios and fetch.


46. How do you update JSON in JavaScript?

You can directly update keys:

obj.name = "New Name";

47. What is a JSON merge patch?

A JSON merge patch is a partial update to a JSON document.


48. Can you use JSON with Redux?

Yes, JSON is used to serialize the state for Redux.


49. What is the maximum size of a JSON file?

There is no fixed limit, but practical limits depend on the parser and system resources.


50. How do you test JSON APIs?

Use tools like Postman or write test scripts using libraries like Mocha or Jest.

Total
0
Shares
Previous Post

Enable Checkout Terms and Privacy Checkbox on Woocommerce 9+

Related Posts