Skip to main content

validate_yaml_json_schema

Function validate_yaml_json_schema 

Source
pub fn validate_yaml_json_schema(value: &Value) -> Result<()>
Expand description

Validate a value against the YAML 1.2 JSON-compatible schema level.

Not the JSON Schema 2020-12 document validation language. This validates that a value uses only types that round-trip through JSON: nulls, booleans, integers, finite floats, strings, sequences, and mappings — i.e. the YAML 1.2.2 §10.2 JSON Schema. A native validator for the https://json-schema.org/draft/2020-12/schema language is tracked for a future release; this name space is reserved.

The JSON schema extends the failsafe schema with:

  • Null (tag:yaml.org,2002:null)
  • Boolean (tag:yaml.org,2002:bool)
  • Integer (tag:yaml.org,2002:int)
  • Float (tag:yaml.org,2002:float)
  • Strings, sequences, and mappings from failsafe

§Errors

Returns an error if the value contains types not supported by JSON schema (primarily tagged values with non-standard tags) or non-finite floats (NaN / Infinity), which JSON cannot represent.

§Examples

use noyalib::{validate_yaml_json_schema, Value};

// Valid JSON schema values
let valid = Value::from(42);
assert!(validate_yaml_json_schema(&valid).is_ok());

let null = Value::Null;
assert!(validate_yaml_json_schema(&null).is_ok());