Skip to main content

json_to_monty

Function json_to_monty 

Source
pub fn json_to_monty(value: Value) -> MontyObject
Available on crate features code and embedded-python only.
Expand description

Convert a host JSON value into a Monty value, to be injected into a script (an input binding, a host function result, a resolved name, …).

The mapping is the obvious one. A JSON integer that fits in i64 becomes an int; anything larger (or fractional) becomes a float. Objects become dicts keyed by their string keys, preserving insertion order. Nesting beyond the conversion depth limit degrades to a placeholder string.

§Example

use adk_code::embedded_python::{json_to_monty, monty_types::MontyObject};
use serde_json::json;

assert_eq!(json_to_monty(json!(42)), MontyObject::Int(42));