Python CLI tool for validating API JSON responses against configurable rules. Supports nested JSON, array indexing, and QA/Postman workflows.
While learning QA Engineering and API Testing with Postman, I wanted to get my hands super dirty and build a project that forced me to learn the ins and outs of API response validation with Python. To this end, I built a Python CLI validator that checks an API response in Postman against prescribed, configurable rules.
The tool allows the user to:
- Validate required fields
- Validate expected data types
- Support nested JSON via dot-path syntax
- Support array/list indexing (movies[0].title)
- Generate structured JSON validation reports
- CLI workflow for API/Postman testing
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
{
"required_keys": [
"userId",
"id",
"title",
"body"
],
"expected_types": {
"userId": "integer",
"id": "integer",
"title": "string",
"body": "string"
}
}
Passing example:
{
"overall_passed": true,
"all_checks": [
{
"path": "userId",
"check_type": "required",
"passed": true
},
{
"path": "id",
"check_type": "required",
"passed": true
},
{
"path": "title",
"check_type": "required",
"passed": true
},
{
"path": "body",
"check_type": "required",
"passed": true
},
{
"path": "userId",
"check_type": "type",
"expected_type": "integer",
"passed": true
},
{
"path": "id",
"check_type": "type",
"expected_type": "integer",
"passed": true
},
{
"path": "title",
"check_type": "type",
"expected_type": "string",
"passed": true
},
{
"path": "body",
"check_type": "type",
"expected_type": "string",
"passed": true
}
]
}
Failing example:
{
"overall_passed": false,
"all_checks": [
{
"path": "userId",
"check_type": "required",
"passed": true
},
{
"path": "id",
"check_type": "required",
"passed": true
},
{
"path": "title",
"check_type": "required",
"passed": true
},
{
"path": "body",
"check_type": "required",
"passed": false,
"reason": "missing key"
},
{
"path": "userId",
"check_type": "type",
"expected_type": "integer",
"passed": false,
"reason": "wrong type",
"actual_type": "str"
},
{
"path": "id",
"check_type": "type",
"expected_type": "integer",
"passed": true
},
{
"path": "title",
"check_type": "type",
"expected_type": "string",
"passed": true
},
{
"path": "body",
"check_type": "type",
"expected_type": "string",
"passed": false,
"reason": "missing key"
}
]
}
Building this API validation tool forced me to learn many key skills, most notably:
- Nested JSON traversal
- List index validation
- CLI argument parsing with argparse
- JSON schema logic
- Debugging validation edge cases