> ## 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 un value en l encodant avec json.encode semantics puis en decodant le generated JSON en 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 a encode et decode. Supported JSON values font un round-trip with JSON; unsupported types sont encodes en null sauf si encode options demandent une erreur.
  </ParamField>

  <ParamField path={"options"} type={"EncodeOptions"}>
    Optional encode options passees a l encode step, comme sortKeys, emptyTableAsArray, errorOnUnsupported, encodeInvalidNumbersAsNull, maxDepth, pretty et indent.
  </ParamField>

  ## Retours

  <ResponseField name={"clone"} type={"any"}>
    Decoded value produit depuis le encoded JSON. Objects et arrays sont des new tables avec JSON kind markers du decoder; JSON null values deviennent json.null.
  </ResponseField>

  ## Types

  ### EncodeOptions

  Contrôle la sérialisation et le formatage JSON.

  | Name                         | Type      | Required | Description                                                              |
  | ---------------------------- | --------- | -------- | ------------------------------------------------------------------------ |
  | `pretty`                     | `boolean` | No       | Permet une sortie JSON formatée et multiligne.                           |
  | `sortKeys`                   | `boolean` | No       | Trie les clés d'objet avant l'encodage.                                  |
  | `emptyTableAsArray`          | `boolean` | No       | Encode une table vide sous forme de tableau au lieu d'un objet.          |
  | `errorOnUnsupported`         | `boolean` | No       | Génère une erreur au lieu de remplacer des valeurs non prises en charge. |
  | `encodeInvalidNumbersAsNull` | `boolean` | No       | Encode NaN et les nombres infinis en JSON null.                          |
  | `maxDepth`                   | `integer` | No       | Définit la profondeur d'imbrication maximale, comprise entre 1 et 4 096. |
  | `indent`                     | `string`  | No       | Définit la chaîne d'indentation, limitée à 32 caractères.                |

  ## Exemple

  Fais un round-trip d un JSON-compatible value with json.encode et json.decode avant de modifier 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>
