Deep Copy

Is this the most efficient deep copy I can do? Or can someone suggest improvements? I haven’t tested it on much yet, but I have a requirement to deep copy some structures. Yes, it’s using recursion, but I’m doing it in the agent, there’s no risk of self-reference as the tables and arrays are decoded from JSON and it’s highly unlikely that it’ll deal with anything deeper than 5 levels.

`
function deepCopy(container){

switch(typeof(container)){
    case "table":
        local result = clone container;
        foreach( k,v in container)
            result[k] = deepCopy(v);
        return result;
    case "array":
        return container.map(deepCopy);
    default:
        return container;
}

}`

I’d be tempted to http.jsonencode it and then http.jsondecode it again. It might be more efficient, because it’ll do most of the work in C, rather than squirrel. Also, if was originally JSON, you’re not losing any fidelity, hopefully.