Top JSON Interview Questions(2025)
Question: What is the structure of a JSON object?
Answer:
A JSON object is a collection of key-value pairs and is the most common structure used in JSON (JavaScript Object Notation) to represent data. The general structure of a JSON object is similar to that of a JavaScript object, but it follows a specific format and syntax.
Basic Structure:
{
"key1": value1,
"key2": value2,
"key3": value3
}
- Curly Braces
{}
: A JSON object is enclosed in curly braces{}
. - Key-Value Pairs: Inside the curly braces, there are one or more key-value pairs, where:
- Key: A string that represents the name of the property. It must be enclosed in double quotes (
"key"
). - Value: The data or information associated with the key. The value can be one of the following:
- A string (enclosed in double quotes),
- A number (integer or float),
- An array (an ordered list of values),
- A boolean (
true
orfalse
), - null (indicating absence of value),
- Another JSON object (nested objects).
- Key: A string that represents the name of the property. It must be enclosed in double quotes (
Each key-value pair is separated by a comma.
Example of a JSON Object:
{
"name": "John",
"age": 30,
"isStudent": false,
"address": {
"street": "123 Main St",
"city": "New York",
"zipCode": "10001"
},
"courses": ["Math", "Science", "History"],
"graduated": null
}
In this example:
"name"
,"age"
,"isStudent"
,"address"
,"courses"
, and"graduated"
are the keys."John"
,30
,false
, the nested JSON object for"address"
, the array for"courses"
, andnull
are the values.
Breakdown of JSON Object Structure:
- Key-Value Pairs: Each key is a string, followed by a colon
:
, and the value can be of various data types (string, number, boolean, null, array, or another object). - Nested Objects: Values in a JSON object can themselves be JSON objects, allowing for a hierarchical or nested structure.
- Arrays: JSON objects can also contain arrays, which are ordered lists of values. An array is enclosed in square brackets
[]
, and its values are separated by commas.
Example Breakdown:
{
"name": "John", // String value
"age": 30, // Number value
"isStudent": false, // Boolean value
"address": { // Nested JSON object
"street": "123 Main St",
"city": "New York",
"zipCode": "10001"
},
"courses": ["Math", "Science", "History"], // Array
"graduated": null // Null value
}
"address"
is a nested JSON object, containing its own set of key-value pairs."courses"
is an array containing strings."graduated"
is a null value, meaning no data or that the person is not marked as graduated.
Rules for a JSON Object:
-
Keys: Keys must be strings enclosed in double quotes
" "
. They cannot be single quotes' '
. -
Values: Values can be of the following types:
- String: Must be enclosed in double quotes (
"value"
). - Number: No quotes are needed (
42
,3.14
). - Boolean:
true
orfalse
(no quotes). - Null:
null
(no quotes). - Array: An ordered collection of values inside square brackets (
[]
). - Object: Another JSON object enclosed in curly braces (
{}
). This allows for nested objects.
- String: Must be enclosed in double quotes (
-
Commas: Key-value pairs within a JSON object are separated by commas. However, there should be no trailing comma after the last key-value pair in an object.
-
Whitespace: JSON allows for whitespace (spaces, tabs, and newlines) to be used freely for readability. It does not affect the data itself.
Summary of a JSON Object Structure:
- Curly braces
{}
enclose the JSON object. - Key-value pairs are written in the format
"key": value
, where the key is a string and the value can be any of the allowed types (string, number, boolean, null, array, or object). - Comma-separated key-value pairs inside the curly braces.
- Keys must always be strings enclosed in double quotes.
- Values can be strings, numbers, booleans, null, arrays, or nested objects.
Question: What data types are supported in JSON?
Answer:
JSON (JavaScript Object Notation) supports a limited set of data types for both keys (which are always strings) and values. These data types are simple, lightweight, and designed for easy data exchange. Below are the data types supported in JSON:
1. String
-
A string in JSON is a sequence of characters enclosed in double quotes (
" "
). -
Strings can contain letters, digits, special characters, spaces, and escape sequences.
Example:
"name": "John Doe"
2. Number
-
A number in JSON can be an integer or a floating-point number.
-
JSON does not distinguish between integers and floating-point numbers. Both are represented by the same
Number
type. -
JSON numbers can be positive or negative, and they can also include an exponent (scientific notation).
Example:
"age": 30 "temperature": 36.6 "balance": -200.50 "largeNumber": 1.5e10
3. Boolean
-
A boolean value in JSON can either be
true
orfalse
(without quotes).Example:
"isStudent": false "isActive": true
4. Null
-
The null type represents the absence of any value. It is written as
null
(without quotes).Example:
"address": null "phone": null
5. Array
-
An array in JSON is an ordered list of values enclosed in square brackets (
[ ]
). -
The values inside the array can be of any data type, including strings, numbers, booleans, objects, other arrays, or null.
Example:
"colors": ["red", "green", "blue"] "numbers": [1, 2, 3, 4] "mixedArray": ["apple", 42, true, null]
6. Object
-
A JSON object is a collection of key-value pairs, where each key is a string and each value can be any valid JSON data type (string, number, boolean, null, array, or another object).
-
Objects are enclosed in curly braces (
{ }
).Example:
"person": { "name": "John", "age": 30, "isStudent": false }
Here,
"person"
is a key, and the value is another object with keys"name"
,"age"
, and"isStudent"
.
Summary of Supported Data Types in JSON:
Data Type | Description | Example |
---|---|---|
String | A sequence of characters enclosed in double quotes. | "name": "John Doe" |
Number | Integer or floating-point number (no distinction). | "age": 30 , "price": 99.99 |
Boolean | Represents true or false values. | "isActive": true |
Null | Represents no value or the absence of data. | "address": null |
Array | An ordered list of values enclosed in square brackets. | "colors": ["red", "green", "blue"] |
Object | A collection of key-value pairs enclosed in curly braces. | "person": {"name": "John", "age": 30} |
Notes:
- JSON does not support:
- Functions or methods.
- Dates (although dates can be represented as strings in a specific format like ISO 8601).
- Undefined values.
- JSON is a text-based format, so everything, except for booleans, null, and numbers, is stored as a string (e.g.,
"true"
,"false"
, and"null"
).
Read More
If you can’t get enough from this article, Aihirely has plenty more related information, such as JSON interview questions, JSON interview experiences, and details about various JSON job positions. Click here to check it out.
Tags
- JSON
- JavaScript
- JSON Parsing
- JSON Stringify
- JSON Validation
- JSON Object
- JSON Array
- JSONP
- JSON Web Tokens
- JWT
- HTTP Requests
- API Integration
- JSON Schema
- Data Types in JSON
- JSON vs XML
- Content Type
- JSON Comments
- Accessing JSON Values
- JSON Handling
- Large JSON Data
- Security in JSON
- Cross Site Scripting
- JSON Injection
- JSON Web Tokens Authentication
- JSON Usage
- JSON Data Transfer
- JSON Methods
- JSON Validation Techniques