Skip to main content

safe_parse

Function safe_parse 

Source
pub fn safe_parse(text: &str) -> SafeOutcome
Expand description

Parse JSON text and fold every outcome into a SafeOutcome.

Runs with both actions at Action::Error and safe on. A clean parse returns SafeOutcome::Value. A forbidden key returns SafeOutcome::Violation. Malformed JSON returns SafeOutcome::Malformed. This never returns an error type.

ยงExamples

use secure_json_parse::{safe_parse, SafeOutcome};

match safe_parse(r#"{"a": 1}"#) {
    SafeOutcome::Value(v) => assert_eq!(v, serde_json::json!({"a": 1})),
    _ => panic!("expected a value"),
}