pub struct JSONSchema<'a> { /* private fields */ }Implementations§
Source§impl<'a> JSONSchema<'a>
impl<'a> JSONSchema<'a>
Sourcepub fn new<T: IntoIterator<Item = (&'a str, Box<dyn Validator + 'a>)>>(
rules: T,
) -> Self
pub fn new<T: IntoIterator<Item = (&'a str, Box<dyn Validator + 'a>)>>( rules: T, ) -> Self
Create a new JSONSchema instance with the given rules.
§Example
use jsonparser::{JSONSchema, StringType, NumberType};
let schema = JSONSchema::new([
("name", StringType::new().min_length(6).boxed()),
("age", NumberType::new().gt(18.0).boxed())
]);Sourcepub fn validate(&self, value: &JSONValue) -> Result<JSONValue, String>
pub fn validate(&self, value: &JSONValue) -> Result<JSONValue, String>
Validate the given JSONValue against the schema.
§Example
use jsonparser::{JSONValue, JSONSchema, StringType, NumberType};
let schema = JSONSchema::new([
("name", StringType::new().min_length(3).trim().boxed()),
("age", NumberType::new().gt(18.0).boxed())
]);
let json = JSONValue::Object({ /* ... */ });
match schema.validate(&json) {
Ok(value: JSONValue) => println!("{:?}", value),
Err(e) => eprintln!("Invalid JSON: {}", e)
}Auto Trait Implementations§
impl<'a> Freeze for JSONSchema<'a>
impl<'a> !RefUnwindSafe for JSONSchema<'a>
impl<'a> !Send for JSONSchema<'a>
impl<'a> !Sync for JSONSchema<'a>
impl<'a> Unpin for JSONSchema<'a>
impl<'a> !UnwindSafe for JSONSchema<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more