Skip to main content

parse_yaml

Function parse_yaml 

Source
pub fn parse_yaml(content: &str) -> Result<Value, String>
Expand description

Parse a YAML string into a serde_json::Value.

Accepts both mapping (object) and array top-level documents. Scalar YAML (a bare string, number, or boolean) is rejected because none of the DevOps formats use a scalar root.

§Errors

Returns Err(String) when:

  • The input is not valid YAML syntax.
  • The YAML root is a scalar (null, bool, number, or string) rather than a mapping or array.

§Example

use devops_validate::validator::parse_yaml;

let data = parse_yaml("key: value").unwrap();
assert!(data.is_object());

assert!(parse_yaml("just a string").is_err());