json-test
A testing library for JSON Path assertions in Rust, providing a fluent API for validating JSON structures in tests.
Features
- 🔍 JSONPath-based value extraction and validation
- ⛓️ Chainable, fluent assertion API
- 🎯 Type-safe operations
- 🧩 Property existence and value validation
- 📝 String pattern matching with regex support
- 🔢 Numeric comparisons
- 📦 Array and object validation
- 🎨 Custom matcher support
Quick Start
Add to your Cargo.toml
:
[]
= "0.1"
Basic usage:
use JsonTest;
use json;
Main Features
Path Assertions
test.assert_path
.exists
.has_property
.has_property_value;
String Operations
test.assert_path
.is_string
.contains_string
.matches_pattern;
Numeric Comparisons
test.assert_path
.is_number
.is_greater_than
.is_less_than;
Array Operations
test.assert_path
.is_array
.has_length
.contains;
Property Matching
test.assert_path
.has_properties
.properties_matching
.count
.and
.has_property_matching;
Custom Matchers
test.assert_path
.matches;
Examples
Looking for more examples? Check out the examples/
directory which showcases:
- Basic JSON validation patterns
- Advanced JSONPath queries
- Property matching capabilities
Error Messages
The library provides clear, test-friendly error messages:
Property 'email' not found at $.user
Available properties: name, age, roles
Array at $.user.roles has wrong length
Expected: 3
Actual: 2
Status
This library is in active development (0.1.x). While the core API is stabilizing, minor breaking changes might occur before 1.0.
Roadmap
- Enhanced array operations
- Deep property traversal
- Improved string operations
- Additional numeric assertions
Contributing
Contributions are welcome! Please see our Contributing Guide for details.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.