Skip to main content

validate_json

Function validate_json 

Source
pub fn validate_json(s: &str) -> Result<(), String>
Expand description

Minimal JSON structural validator.

Returns Ok(()) if s is a syntactically valid JSON value (object, array, string, number, true/false/null). Does NOT validate semantics (e.g. duplicate keys are accepted).

Hand-rolled, no serde_json dependency at the public surface.

ยงExample

use dev_fixtures::mock::json_array::validate_json;

assert!(validate_json("[]").is_ok());
assert!(validate_json("[{\"x\": 1}]").is_ok());
assert!(validate_json("[invalid]").is_err());