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.
parse returns nil plus an error string past the size or depth cap. dump raises a Lua error past the depth cap.
See globals Error shapes and Limits and errors.
Unsupported Luau types serialize as JSON null. A sparse array (missing numeric keys) dumps its holes 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 indent.Nesting depth and parse size are capped.
See Limits and errors.
src/bindings/geode/GeodeSmallBindings.cppsrc/bindings/geode/JsonConvert.hppsrc/bindings/geode/JsonConvert.cpptools/luau_codegen/extra_bindings/json.dluau