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

> Clone value bang cach encoding voi json.encode semantics roi decoding generated JSON tro lai thanh Lua values.

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

  ## Đối số

  <ParamField path={"value"} type={"any"} required>
    Value de encode va decode. Supported JSON values round-trip qua JSON; unsupported types duoc encode thanh null tru khi encode options yeu cau error.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options duoc truyen vao encode step, nhu sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, pretty va indent.
  </ParamField>

  ## Giá trị trả về

  <ResponseField name={"clone"} type={"any"}>
    Decoded value duoc tao tu encoded JSON. Objects va arrays la new tables voi JSON kind markers tu decoder; JSON null values tro thanh json.null.
  </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ụ

  Round-trip JSON-compatible value qua json.encode va json.decode truoc khi thay doi nested values.

  ```lua theme={null}
  local original = {
      profile = { name = "Guest" },
  }

  local copy = json.clone(original)
  copy.profile.name = "Developer"

  print(original.profile.name)
  print(copy.profile.name)
  print(json.type(copy))
  ```
</div>
