Skip to main content

validate

Function validate 

Source
pub fn validate(bytes: &[u8]) -> Result<(), Error>
Expand description

Checks that bytes hold one JSON value, with nothing but whitespace around it.

It reads them once. Their UTF-8 is checked inside strings, and only where a string has a byte that is not ASCII: outside strings, the grammar admits ASCII alone.

assert!(json_cursor::validate(br#"{"a": [1, 2.5, "x"]}"#).is_ok());
assert!(json_cursor::validate(br#"{"a": 1,}"#).is_err());