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

> Clones a value by encoding it with json.encode semantics and decoding the generated JSON back into Lua values.

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

  ## Arguments

  <ParamField path={"value"} type={"any"} required>
    Value to encode and decode. Supported JSON values round-trip with JSON; unsupported types encode as null unless encode options request an error.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options passed to the encode step, such as sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, pretty, and indent.
  </ParamField>

  ## Returns

  <ResponseField name={"clone"} type={"any"}>
    Decoded value produced from the encoded JSON. Objects and arrays are new tables with JSON kind markers from the decoder; JSON null values decode to json.null.
  </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

  Round-trip a JSON-compatible value through json.encode and json.decode before changing 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>
