JSON (JavaScript Object Notation) is the language APIs speak. Every request body you send and every response you receive will be in JSON. If you can't read JSON, you can't test APIs. Period.
Good news — JSON is dead simple. If you can read a grocery list, you can read JSON. It's just key-value pairs wrapped in curly braces.
{
"name": "Priya Sharma",
"age": 26,
"isActive": true,
"balance": 45000.50,
"address": null
}That's it. Keys on the left (always in double quotes). Values on the right. Separated by a colon. Multiple pairs separated by commas. The whole thing wrapped in curly braces {}.
| Type | Example | Notes |
|---|---|---|
| String | "Priya Sharma" | Always in double quotes. Not single quotes. |
| Number | 26, 45000.50 | No quotes. Can be integer or decimal. |
| Boolean | true, false | No quotes. Lowercase only. |
| Null | null | No quotes. Means "no value." |
| Array | ["a", "b", "c"] | Ordered list in square brackets. |
| Object | { "key": "value" } | Nested JSON inside curly braces. |
Common mistake that breaks APIs: using single quotes instead of double quotes. JSON requires double quotes for keys and string values. { 'name': 'Priya' } is INVALID JSON. { "name": "Priya" } is correct. Your API will reject it with a 400 Bad Request.
Objects can contain other objects. This is how real API responses look — data isn't flat, it's layered.
{
"id": "ACC-001",
"holder": {
"name": "Priya Sharma",
"contact": {
"email": "priya@example.com",
"phone": "9876543210"
}
},
"balance": 45000.50,
"type": "savings"
}To access Priya's email, you navigate: root → holder → contact → email. In testing tools, you'd write: response.holder.contact.email. This is called "dot notation" and you'll use it constantly.
{
"accountId": "ACC-001",
"transactions": [
{
"id": "TXN-001",
"type": "credit",
"amount": 50000,
"date": "2024-01-15"
},
{
"id": "TXN-002",
"type": "debit",
"amount": 5000,
"date": "2024-01-16"
},
{
"id": "TXN-003",
"type": "debit",
"amount": 2000,
"date": "2024-01-17"
}
],
"totalTransactions": 3
}Arrays use square brackets []. They hold ordered lists. Each item can be a string, number, object, or even another array. To access the first transaction's amount: response.transactions[0].amount (arrays are 0-indexed).
// Pattern 1: Paginated list response
{
"data": [ ... ],
"page": 1,
"totalPages": 5,
"totalItems": 48
}
// Pattern 2: Error response
{
"error": {
"code": "INSUFFICIENT_FUNDS",
"message": "Account balance is too low for this transfer",
"field": "amount"
}
}
// Pattern 3: Wrapper with metadata
{
"status": "success",
"data": { ... },
"timestamp": "2024-01-15T10:30:00Z",
"requestId": "req-abc-123"
}Key Point: When testing, validate the STRUCTURE of JSON (are all keys present?), the TYPES (is balance a number, not a string?), and the VALUES (is the amount correct?). All three matter.
Use jsonlint.com or your editor's JSON formatter to validate JSON. One missing comma or extra bracket will break everything. When writing test data, always validate your JSON first.
Q: What is JSON and why is it used in APIs?
A: JSON — JavaScript Object Notation — is a lightweight data format that's easy for humans to read and machines to parse. APIs use it because it's simple (key-value pairs), language-independent (every programming language can parse it), and lightweight (smaller than XML). It supports strings, numbers, booleans, null, arrays, and nested objects — which covers any data structure an API needs.
Q: How do you access nested data in a JSON response?
A: Using dot notation or bracket notation. For an object like { "user": { "address": { "city": "Mumbai" } } }, you access the city as response.user.address.city. For arrays, use the index: response.transactions[0].amount gives the first transaction's amount. In testing tools like Postman, you use pm.response.json().user.address.city to extract nested values.
Key Point: JSON is key-value pairs. Objects use {}, arrays use []. Master dot notation — you'll use it in every single API test.