From 5eb89be68246f1e5a8cd28e48d5cec75921ca97a Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 10 Oct 2022 00:32:57 -0400 Subject: feat(tvix/eval): Implement builtins.fromJSON Using `serde_json` for parsing JSON here, plus an `impl FromJSON for Value`. The latter is primarily to stay "dependency light" for now - likely going with an actual serde `Deserialize` impl in the future is going to be way better as it allows saving significantly on intermediary allocations. Change-Id: I152a0448ff7c87cf7ebaac927c38912b99de1c18 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6920 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/builtins/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tvix/eval/src/builtins') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 1ed59ffdc8ed..c0dce868c6fc 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -271,6 +271,11 @@ fn pure_builtins() -> Vec { Ok(res) }, ), + Builtin::new("fromJSON", &[true], |args: Vec, _: &mut VM| { + let json_str = args[0].to_str()?; + let json: serde_json::Value = serde_json::from_str(&json_str)?; + json.try_into() + }), Builtin::new("genList", &[true, true], |args: Vec, vm: &mut VM| { let len = args[1].as_int()?; (0..len) -- cgit 1.4.1