[−][src]Function jsonprima::validate
pub fn validate(code: &str) -> Vec<Error>
Validate a JSON document based on RFC 8259 latest standard.
This function returns when encounter an error, i.e. it is not error tolerant.
Notes
- There is no limit to the size of the provided text to validate.
- There is no limit to the nesting of the JSON document.
- Ignores BOM, if it is present in the beginning of a JSON document, without failing.
Examples
// A valid JSON document. let text: &str = "[true, false]"; let errors = jsonprima::validate(&text); assert!(errors.is_empty()); // No errors, valid JSON document.
// Invalid `true` root value in JSON document. let text: &str = "trua"; let errors = jsonprima::validate(&text); assert_eq!(errors.get(0).unwrap().err.code(), "E105"); assert_eq!(errors.get(0).unwrap().index_start, 0); assert_eq!(errors.get(0).unwrap().index_end, 4);