geode.json converts between JSON text and Luau values,
using the same JSON model as geode.Mod.getSavedValue and setSavedValue.
JSON types map to Lua as boolean, number, string, nil (null), array table, and object table.
Past depth and size limits, tuple APIs fail recoverably and dump raises.
See globals Error shapes and Limits and errors.
Unsupported Luau types serialize as JSON null.
geode.json.parse(text: string) -> (any?, string?)Parses a JSON string into a Luau value. On success returns the value. On failure uses globals Error shapes.
local value, err = geode.json.parse('{"a":[1,2,3]}')
if not value then
print("bad json: " .. err)
else
print(value.a[2]) -- 2
endgeode.json.dump(value: any, indent: number?) -> stringSerializes a Luau value to a JSON string.
- If
#table > 0, the table becomes a JSON array. Only numeric keys1..#tableare kept. String keys are dropped. - Otherwise the table becomes a JSON object. Only string keys are kept.
indentcontrols formatting. The default is compact. A positive number indents with that many spaces, and-1indents with tabs.
geode.json.dump({ x = true }) -- '{"x":true}'
geode.json.dump({ 1, 2, 3 }, 2) -- pretty-printed array, 2-space indentNesting depth and parse size are capped.
See Limits and errors.
src/bindings/geode/GeodeSmallBindings.cppsrc/bindings/geode/JsonConvert.hpptools/luau_codegen/extra_bindings/json.dluau