pub fn parse(text: &str, options: &Options) -> Result<Option<Value>, Error>Expand description
Parse JSON text and apply prototype-poisoning checks.
On success returns Ok(Some(value)). When safe is on and a violation is
found, returns Ok(None). A malformed input gives Error::Syntax; a
violation under Action::Error gives Error::ForbiddenProperty.
Scalars and null skip scanning and are returned as is. Objects and arrays
are walked.
§Errors
Returns Error::Syntax if text is not valid JSON, or
Error::ForbiddenProperty if a forbidden key is found and the matching
Action is Action::Error with safe off.
§Examples
use secure_json_parse::{parse, Action, Options};
let opts = Options::default().constructor_action(Action::Remove);
let v = parse(r#"{"constructor": {"prototype": {}}, "a": 1}"#, &opts)
.unwrap()
.unwrap();
assert_eq!(v, serde_json::json!({"a": 1}));