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

> Real JSON encoder 를 사용해 Lua value 를 JSON string 으로 serialize 합니다. json.stringify 는 같은 function 으로 등록되어 있습니다.

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

  ## 인수

  <ParamField path={"value"} type={"any"} required>
    encode 할 Value 입니다. nil, booleans, numbers, strings, tables, json.null 은 직접 처리됩니다. Unsupported Lua types 는 errorOnUnsupported 가 true 가 아니면 null 로 encode 됩니다.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options. boolean 은 pretty output 을 전환합니다. number 는 0.16 으로 clamp 된 spaces 수로 pretty output 을 활성화합니다. string 은 해당 indent 로 pretty output 을 활성화합니다. table 은 pretty, sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, indent 를 설정할 수 있습니다.
  </ParamField>

  ## 반환값

  <ResponseField name={"json"} type={"string"}>
    Encoded JSON string. Encoding errors 는 Luau errors 로 throw 됩니다.
  </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자로 제한되는 들여쓰기 문자열을 설정합니다.      |

  ## 예제

  JSON-compatible values 를 encode 하고 empty array 가 array 로 유지되어야 하면 json.array 를 사용합니다.

  ```lua theme={null}
  local payload = {
      name = "Real",
      enabled = true,
      tags = json.array({ "api", "docs" }),
      missing = json.null,
  }

  local text = json.encode(payload, {
      sortKeys = true,
  })

  print(text)
  ```
</div>
