> ## 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 Lua value thanh readable formatted JSON string bang Real JSON encoder. json.pretty duoc dang ky vao cung function.

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

  ## Đối số

  <ParamField path={"value"} type={"any"} required>
    Value duoc encoded. nil, booleans, numbers, strings, tables va json.null duoc xu ly truc tiep. Unsupported Lua types duoc encoded thanh null tru khi errorOnUnsupported la true.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options. json.encodePretty doc cung options nhu json.encode, sau do ep pretty thanh true. Khong co options thi dung two-space indent. number dat indent width duoc clamp ve 0.16, string dat indent text, va table co the dat sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth va indent.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"json"} type={"string"}>
    Readable formatted JSON string. Encoding errors duoc throw nhu Luau errors.
  </ResponseField>

  ## Kiểu

  ### EncodeOptions

  Kiểm soát việc tuần tự hóa và định dạng JSON.

  | Name                         | Type      | Required | Mô tả                                                         |
  | ---------------------------- | --------- | -------- | ------------------------------------------------------------- |
  | `pretty`                     | `boolean` | No       | Cho phép xuất JSON nhiều dòng, được định dạng.                |
  | `sortKeys`                   | `boolean` | No       | Sắp xếp các khóa đối tượng trước khi mã hóa.                  |
  | `emptyTableAsArray`          | `boolean` | No       | Mã hóa một bảng trống thành một mảng thay vì một đối tượng.   |
  | `errorOnUnsupported`         | `boolean` | No       | Phát sinh lỗi thay vì thay thế các giá trị không được hỗ trợ. |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Mã hóa NaN và số vô hạn dưới dạng JSON null.                  |
  | `maxDepth`                   | `integer` | No       | Đặt độ sâu lồng tối đa, được kẹp từ 1 đến 4096.               |
  | `indent`                     | `string`  | No       | Đặt chuỗi thụt lề, giới hạn ở 32 ký tự.                       |

  ## Ví dụ

  Encode JSON-compatible values thanh readable formatted JSON voi 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>
