json_mask/
lib.rs

1//! [![github]](https://github.com/LittleBoxOfSunshine/json-mask) [![crates-io]](https://crates.io/crates/json_mask) [![docs-rs]](https://docs.rs/json_mask)
2//!
3//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs
6//!
7//! <br>
8//!
9//! This library provides [`mask::JsonMasker`] which accepts a [JSON Schema](https://json-schema.org/)
10//! document.
11//!
12//! An example use case is an API where the backend generates the latest response version, but
13//! applies the mask to transform the latest response into other API versions to satisfy backwards
14//! compatibility.
15//!
16//! This is an early build where the input validation is more flexible. Based on real world usage
17//! the first stable release will probably restrict to formal schema draft standards and/or allow
18//! you to restrict to specific ones.
19//!
20//! # Examples
21//! - Use generate a mask with [`from_str`] or [`from_reader`] and apply it to a document.
22//!
23//!   ```
24//!   use json_mask::from_str;
25//!   use json_mask::JsonMasker;
26//!   use json_mask::ValidJsonSchema;
27//!
28//!   let mut document = serde_json::from_str(r#"{ "foo": 1, "bar": 2}"#).unwrap();
29//!   let schema = r#"
30//!   {
31//!     "$schema": "http://json-schema.org/draft-04/schema",
32//!     "title": "Demo Schema",
33//!     "description": "Demo",
34//!     "type": "object",
35//!     "properties": {
36//!       "foo": {
37//!         "type": "integer"
38//!       }
39//!     }
40//!   }
41//!   "#;
42//!
43//!   let mask = from_str(schema).unwrap();
44//!   let masker = JsonMasker::new(mask);
45//!   masker.mask(&mut document);
46//!
47//!   assert_eq!(r#"{"foo":1}"#, serde_json::to_string(&document).unwrap())
48//!   ```
49//!
50
51mod mask;
52
53pub use mask::from_reader;
54pub use mask::from_str;
55pub use mask::JsonMasker;
56pub use mask::Mask;
57pub use mask::ParseError;
58pub use mask::ValidJsonSchema;