https://github.com/thebearingedge/ok
:ok_hand: Alright JSON Object validation.
https://github.com/thebearingedge/ok
json rust serde-json validation
Last synced: 4 months ago
JSON representation
:ok_hand: Alright JSON Object validation.
- Host: GitHub
- URL: https://github.com/thebearingedge/ok
- Owner: thebearingedge
- Created: 2018-12-28T00:00:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-06T21:40:44.000Z (almost 7 years ago)
- Last Synced: 2025-05-28T12:44:22.148Z (5 months ago)
- Topics: json, rust, serde-json, validation
- Language: Rust
- Homepage:
- Size: 64.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ok
--
[](https://travis-ci.org/thebearingedge/ok)👌 Alright JSON Object validation.
`ok` is a simple JSON Object schema builder and validation library with an ergonomic API. An `ok` schema is a tree of structs implementing the `OkSchema` trait to validate `serde` JSON values. The validation result will either contain the validated JSON payload or an error listing the unsatisfied validation tests.
### Example
```rust
use ok::{OkSchema, object};let user_schema = object()
.string("username", |string| {
string
.min_length(1)
.max_length(20)
})
.integer("luckyNumber", |integer| {
integer
.not_one_of(vec![2, 3, 5, 7, 11, 13, 17])
});
```In the above example a `user_schema` is created to validate an entire JSON Object modeling a `User`. The `object()` function returns an `ObjectSchema` with `string` and `integer` methods to register subschemas at the properties `"username"` and `"luckyNumber"`, respectively.