API Testing Guide: Tools, Best Practices & JSON Debugging
APIs (Application Programming Interfaces) are the backbone of modern software. Every time you use a mobile app, load a web page, or integrate two services, APIs are making it happen. Testing APIs properly ensures they work correctly, handle errors gracefully, and perform under load. This guide covers everything from basic API concepts to practical testing tools and debugging techniques.
Understanding REST APIs
REST (Representational State Transfer) is the most common API architecture on the web. REST APIs use standard HTTP methods to perform operations on resources identified by URLs.
The four main HTTP methods (CRUD operations):
- GET: Retrieve data (Read) —
GET /api/users/123 - POST: Create new data (Create) —
POST /api/users - PUT/PATCH: Update existing data (Update) —
PUT /api/users/123 - DELETE: Remove data (Delete) —
DELETE /api/users/123
APIs communicate primarily in JSON format. Understanding JSON structure is essential for API work — if you're not familiar, read our JSON format guide first.
Testing APIs with curl
curl is the simplest way to test APIs from the command line. It's pre-installed on Mac, Linux, and Windows 10+.
# GET request
curl https://api.example.com/users
# GET with headers
curl -H "Authorization: Bearer TOKEN" \
-H "Accept: application/json" \
https://api.example.com/users
# POST with JSON body
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@example.com"}'
# Pretty-print JSON response
curl -s https://api.example.com/users | python3 -m json.tool
Pro tip: Pipe curl output through a JSON formatter for readability. Or paste the response into our JSON Formatter which adds syntax highlighting, tree view, and JSONPath queries.
Debugging JSON Responses
When an API returns unexpected data, you need to inspect the JSON carefully. Common issues include:
- Malformed JSON: Missing commas, extra trailing commas, unquoted keys
- Wrong data types: Numbers as strings, null instead of empty arrays
- Missing fields: Expected properties that don't exist in the response
- Nested structure issues: Data buried deeper than expected
Our JSON Formatter helps with all of these. Key features for API debugging:
- Validation: Instantly detects syntax errors with line numbers
- Tree View: Navigate complex nested responses visually
- JSONPath Query: Extract specific values —
data.users[0].name - Diff Mode: Compare two API responses side-by-side to spot changes
Using JSONPath for Data Extraction
JSONPath lets you query specific parts of a JSON document, similar to how XPath works for XML. This is invaluable when working with large API responses.
// Given this response:
{
"data": {
"users": [
{"id": 1, "name": "Alice", "role": "admin"},
{"id": 2, "name": "Bob", "role": "user"}
],
"total": 2
}
}
// JSONPath queries:
data.users[0].name → "Alice"
data.total → 2
data.users[1].role → "user"
Validating API Responses with Regex
Regular expressions are powerful for validating specific patterns in API responses — email formats, date strings, UUIDs, URLs, and more.
// Validate email format
[\w.-]+@[\w.-]+\.\w{2,}
// Validate UUID
[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
// Validate ISO date
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}
// Validate URL
https?:\/\/[\w.-]+(?:\.[\w]+)+[\w.,@?^=%&:\/~+#-]*
Test these patterns with our Regex Tester which includes a built-in pattern library and group highlighting. For a regex tutorial, see our beginner's guide to regex.
API Testing Best Practices
1. Test the Happy Path First
Start with normal, expected inputs. Verify the API returns the correct status code (200 for GET, 201 for POST) and the response body matches the documented schema.
2. Test Error Handling
Good APIs handle errors gracefully. Test:
- Invalid input (wrong types, missing required fields)
- Authentication failures (expired tokens, wrong credentials)
- Resource not found (404 for non-existent IDs)
- Rate limiting (429 Too Many Requests)
- Server errors (how does the API behave under stress?)
3. Check Response Headers
Headers carry important metadata: content type, rate limit remaining, pagination info, caching directives. Don't ignore them.
# Check headers with curl curl -I https://api.example.com/users # Common headers to verify: Content-Type: application/json X-RateLimit-Remaining: 98 X-Total-Count: 150 Cache-Control: max-age=3600
4. Test Pagination
APIs that return lists should support pagination. Test that page size limits work, that navigating to the last page returns correct data, and that out-of-range pages return appropriate responses.
5. Validate Data Types
JSON is loosely typed, so APIs sometimes return inconsistent types. Verify that numbers are numbers (not strings), dates follow a consistent format, and nullable fields handle null correctly.
Encoding and Decoding in API Work
API development frequently involves encoding and decoding data. Common formats you'll encounter:
- Base64: Binary data in API payloads (images, files). Use our Base64 Encoder/Decoder. Learn more in our Base64 guide
- URL encoding: Query parameters with special characters. Use our URL Encoder/Decoder
- JWT tokens: Authentication tokens containing encoded claims. Use our JWT Decoder. Read our JWT guide
- Hash values: Data integrity verification. Use our Hash Generator
Comparing API Responses
When debugging API changes, you often need to compare the "before" and "after" responses. Our JSON Formatter's diff mode highlights exactly what changed between two JSON payloads — additions in green, deletions in red.
This is invaluable when:
- Upgrading API versions and verifying backward compatibility
- Debugging why a frontend feature broke after a backend deploy
- Comparing responses from different environments (staging vs. production)
- Reviewing data migration results
Security Testing Essentials
API security is critical. Basic checks every developer should perform:
- Authentication: Verify unauthenticated requests are rejected
- Authorization: User A shouldn't access User B's data
- Input validation: SQL injection, XSS payloads should be sanitized
- HTTPS: All API endpoints should use TLS encryption
- Rate limiting: Prevent abuse and DDoS attacks
- Sensitive data: Passwords should never appear in responses
For more on security practices, read our password security guide and hash functions guide.
Wootils has everything you need: JSON Formatter (with tree view, JSONPath, diff), Regex Tester, Base64 Encoder, JWT Decoder, and Hash Generator. All free, all in-browser.
Conclusion
Effective API testing combines the right tools with systematic methodology. Start with curl for quick checks, use JSON formatting tools for response inspection, validate patterns with regex, and always test both success and failure cases. Build these practices into your development workflow, and you'll ship more reliable integrations with fewer bugs.