Skip to main content

monty_to_json

Function monty_to_json 

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

Convert a Monty value produced by a script into host JSON.

This is the “natural” projection: JSON-native Python values map to their bare JSON form (42, "hi", [...], {"a": 1}). It is deliberately not serde_json::to_value(obj)MontyObject’s derived Serialize is an externally tagged snapshot format ({"Int": 42}) meant for binary transport, not human-facing JSON. The rare non-JSON-native value (a tuple, bytes, a date, …) degrades to its Python repr string. Nesting beyond the conversion depth limit degrades to a placeholder string.

§Example

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

let list = MontyObject::List(vec![MontyObject::Int(1), MontyObject::Bool(true)]);
assert_eq!(monty_to_json(&list), json!([1, true]));