> ## 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.stringify

> Сериализует Lua value в JSON string через ту же function, что json.encode.

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

  ## Аргументы

  <ParamField path={"value"} type={"any"} required>
    Value для encode. nil, booleans, numbers, strings, tables и json.null обрабатываются напрямую. Unsupported Lua types кодируются как null, если errorOnUnsupported не true.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options. boolean переключает pretty output. number включает pretty output с таким числом spaces, clamp до 0.16. string включает pretty output с этим indent. table может задавать pretty, sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth и indent.
  </ParamField>

  ## Возвраты

  <ResponseField name={"json"} type={"string"}>
    Encoded JSON string. Encoding errors выбрасываются как Luau errors.
  </ResponseField>

  ## Типы

  ### EncodeOptions

  Управляет сериализацией и форматированием JSON.

  | Name                         | Type      | Required | Описание                                                     |
  | ---------------------------- | --------- | -------- | ------------------------------------------------------------ |
  | `pretty`                     | `boolean` | No       | Включает форматированный многострочный вывод JSON.           |
  | `sortKeys`                   | `boolean` | No       | Сортирует ключи объекта перед кодированием.                  |
  | `emptyTableAsArray`          | `boolean` | No       | Кодирует пустую таблицу как массив вместо объекта.           |
  | `errorOnUnsupported`         | `boolean` | No       | Вызывает ошибку вместо замены неподдерживаемых значений.     |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Кодирует NaN и бесконечные числа как значение JSON null.     |
  | `maxDepth`                   | `integer` | No       | Устанавливает максимальную глубину вложенности от 1 до 4096. |
  | `indent`                     | `string`  | No       | Устанавливает строку отступа, ограниченную 32 символами.     |

  ## Пример

  Encode JSON-compatible values через ту же function, что json.encode.

  ```lua theme={null}
  local text = json.stringify({
      status = "ready",
      count = 3,
      tags = json.array({ "stringify", "alias" }),
      missing = json.null,
  }, {
      sortKeys = true,
  })

  print(text)
  ```
</div>
