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

# json.encodePretty

> Serializes a Lua value to a readable formatted JSON string as JSON. json.pretty is registered to the same function.

<div className="real-function-page">
  ```lua theme={null}
  json.encodePretty(value: any, options?: EncodeOptions): string
  ```

  ## Arguments

  <ParamField path={"value"} type={"any"} required>
    Value to encode. nil, booleans, numbers, strings, tables, and json.null are handled directly. Unsupported Lua types encode as null unless errorOnUnsupported is true.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options. json.encodePretty reads the same options as json.encode, then forces pretty to true. Without options, it uses a two-space indent. A number sets the indent width clamped to 0.16, a string sets the indent text, and a table can set sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, and indent.
  </ParamField>

  ## Returns

  <ResponseField name={"json"} type={"string"}>
    Readable formatted JSON string. Encoding errors are thrown as Luau errors.
  </ResponseField>

  ## Types

  ### EncodeOptions

  Controls JSON serialization and formatting.

  | Name                         | Type      | Required | Description                                                 |
  | ---------------------------- | --------- | -------- | ----------------------------------------------------------- |
  | `pretty`                     | `boolean` | No       | Enables formatted, multi-line JSON output.                  |
  | `sortKeys`                   | `boolean` | No       | Sorts object keys before encoding.                          |
  | `emptyTableAsArray`          | `boolean` | No       | Encodes an empty table as an array instead of an object.    |
  | `errorOnUnsupported`         | `boolean` | No       | Raises an error instead of substituting unsupported values. |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Encodes NaN and infinite numbers as JSON null.              |
  | `maxDepth`                   | `integer` | No       | Sets the maximum nesting depth, clamped from 1 to 4096.     |
  | `indent`                     | `string`  | No       | Sets the indentation string, limited to 32 characters.      |

  ## Example

  Encode JSON-compatible values as readable formatted JSON with pretty output forced on.

  ```lua theme={null}
  local text = json.encodePretty({
      name = "Real",
      version = 1,
      features = json.array({ "docs", "examples" }),
      missing = json.null,
  }, {
      sortKeys = true,
  })

  print(text)
  ```
</div>
