pub fn json_to_lua(lua: &Lua, val: Value) -> Result<Value, Error>Expand description
Convert a serde_json::Value to a Lua value.
JSON null maps to the LightUserData(null_ptr) sentinel
(mlua::Value::NULL), which is the same representation lua_to_json
accepts on the way out — so the round-trip is symmetric. Using the
sentinel rather than Lua nil means JSON null values survive being
placed into Lua tables (tables cannot hold nil), so SQL NULL columns
and MCP/LLM JSON payloads do not lose the distinction between “null”
and “absent”. Agents can compare a value against the exposed
std.sql.null constant to detect it.
Note: this differs from mlua-batteries’ std.json.decode, which keeps
the Lua-idiomatic “null → nil” lowering for json.decode itself. Our
bridge paths (sql / kv / mcp / mesh / llm) prefer round-trip fidelity.