1use jrsonnet_evaluator::{IStr, Result, Val, function::builtin, runtime_error};23#[builtin]4pub fn builtin_parse_json(str: IStr) -> Result<Val> {5 let value: Val =6 serde_json::from_str(&str).map_err(|e| runtime_error!("failed to parse json: {e}"))?;7 Ok(value)8}910#[builtin]11pub fn builtin_parse_yaml(str: IStr) -> Result<Val> {12 let needs_synthetic_null = str.trim_end().ends_with("\n---");1314 let mut out = serde_saphyr::from_multiple_with_options::<Val>(15 &str,16 serde_saphyr::Options {17 18 legacy_octal_numbers: true,19 20 budget: None,21 ..Default::default()22 },23 )24 .map_err(|e| runtime_error!("failed to parse yaml: {e}"))?;2526 27 28 if needs_synthetic_null {29 out.push(Val::Null);30 }3132 Ok(if out.is_empty() {33 Val::Null34 } else if out.len() == 1 {35 out.into_iter().next().unwrap()36 } else {37 Val::Arr(out.into())38 })39}