JSON

json.clone

Creates a deep JSON-compatible copy of a value without sharing nested table references.

Syntax

json.clone(value: any): any

Arguments

NameTypeDescription
valueanyNew value to write.

Returns

NameTypeDescription
cloneanyCloned 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)