evaluate_to_json

Function evaluate_to_json 

Source
pub fn evaluate_to_json(source: &str) -> Result<String>
Expand description

Evaluate a Jsonnet snippet and format the result as a JSON string.

§Arguments

  • source - A string slice that holds the Jsonnet source code.

§Returns

A Result containing the formatted JSON string or a JsonnetError.

§Examples

use rs_jsonnet::evaluate_to_json;

let json_str = evaluate_to_json(r#"{ key: "value", items: [1, 2, 3] }"#).unwrap();
let expected_json = serde_json::json!({
  "key": "value",
  "items": [1, 2, 3]
});
assert_eq!(json_str, serde_json::to_string_pretty(&expected_json).unwrap());