Syntax
json.clone(value: any): anyArguments
| Name | Type | Description |
|---|---|---|
value | any | New value to write. |
Returns
| Name | Type | Description |
|---|---|---|
clone | any | Cloned function reference. |
Description
Creates a deep JSON-compatible copy of a value without sharing nested table references.
Call it with 1 parameter(s): value. The argument table explains which values are required and which ones only refine the behavior.
It returns clone (any). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Create a deep JSON-compatible copy before changing nested values.
local original = {
profile = { name = "Guest" },
}
local copy = json.clone(original)
copy.profile.name = "Developer"
print(original.profile.name)
print(copy.profile.name)