> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebind.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# rb.json

> Turn JSON text into Luau values, and Luau values into pretty-printed JSON.

`rb.json` reads JSON text into Luau values and writes Luau values back out as
JSON. A script reaches for it when settings or a reply arrive as JSON text, or
when it has to hand a table on as text.

This script reads a settings string, checks a null field, changes a value and
writes the result back out:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
local text = '{"profile": "default", "sensitivity": 1.5, "hotkey": null, "weapons": []}'
local data = rb.json.parse(text)

rb.log.info("profile", data.profile, data.sensitivity)
if type(data.hotkey) == "userdata" then
  rb.log.warn("no hotkey set")
end

data.sensitivity = 2
rb.log.info(rb.json.stringify(data))  -- "weapons" stays []
```

| Signature | Returns |
| - | - |
| `rb.json.parse(s: string) -> any` | a Luau value; raises `JSON parse error: <reason>` |
| `rb.json.stringify(value: any) -> string` | pretty-printed JSON |

`stringify` raises when the value holds a function, a thread, or a table with
keys that are neither all strings nor a list.

JSON `null` parses to a placeholder value, not `nil`. It is truthy and its key
stays in the table, so `if data.field then` passes for a null field; test
`type(v) == "userdata"` for null. `stringify` writes an empty table as `{}`; an
array that came from `parse` keeps its brackets, even when empty.
`rb.file.read_json` and `write_json` follow the same rules.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.