# StructCopy

Creates a shallow copy of a struct.

Copies top-level keys, values, and arrays in the structure by value; copies nested structures by reference.

## Method Signature

```
StructCopy(struct=[structloose])
```

### Arguments

| Argument | Type     | Required | Description        | Default |
| -------- | -------- | -------- | ------------------ | ------- |
| `struct` | `struct` | `true`   | The struct to copy |         |

## Examples

### Copy a structure and change it. Original structure stays unchanged

[Run Example](https://try.boxlang.io/?code=eJzLrQwuKSpNLlGwVahW4OJUSlRSsFIw1AGykkAsIxArGcQy5qq15sqt9Esth2soBjOc8wsqNRRyYeZooqjScwKqM0URilZQSlFSiAWKm1hzQYxwSc1JLUkFGQJXpaMAshZoWHlRZkmqf2lJQWmJBtRG79RKn8ziEmRLFdQUlBQetU0CkmqYqhCO1gQZCQAMZEy5)

```java
myStruct = { 
	"a" : 1,
	"b" : 2,
	"c" : 3
};
myNewStruct = structCopy( myStruct );
myNewStruct.B = 5;
myNewStruct[ "d" ] = 4;
structDelete( myNewStruct, "c" );
writeOutput( structKeyList( myStruct ) & " → " & structKeyList( myNewStruct ) );

```

Result: b,a,c → b,a,d

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxtkEFrgzAYhs%2FNr3jx1IK09w0P0tGx0wYd9JyaiMGYT2KsjLL%2FviRaUdaL8CXv9%2BTx5UY1XHfIcAfbHD8veEHSECUp23x9vIeJlKkT9vvKDgecKxpQ9NZK48DHXfbWN%2B0Wml%2BlzpLj%2BjJJceM2mybsIuVI7c8jgM7ZvnBwhJLbhoWPtznH0xDcYr0cFUIqhSaqO2hVy%2Bcup8DipZN2ydtNTvGlkZkL4QnkKp8cSXtclNbwZx5QSi8Y4ns2cvK2lUbMZinuvrv8O3YnafBtLWXnlPGDMoXuhexQcLe2zaffHJSrwi24EFI8LXDRgSDPCpoVv8n%2F0FhBQa2SAqWlZi7zKkuycQED71ZvPYr5A2vYsJc%3D)

```java
animals = { 
	COW : "moo",
	PIG : "oink"
};
// Show current animals
Dump( label="Current animals", var=animals );
// Copy animals struct to farm
farm = StructCopy( animals );
// Show farm, looks like animals
Dump( label="Farm after StructCopy()", var=farm );
// Add another animal. Will not affect farm.
StructAppend( animals, {
	CAT : "meow"
} );
// Show animals, now includes cat
Dump( label="Animals with cat added", var=animals );
// Show farm, does not have cat
Dump( label="Farm copied from animals before cat was added", var=farm );

```

## Related

* [StructAppend](/boxlang-language/reference/built-in-functions/struct/structappend.md)
* [StructClear](/boxlang-language/reference/built-in-functions/struct/structclear.md)
* [StructDelete](/boxlang-language/reference/built-in-functions/struct/structdelete.md)
* [StructEach](/boxlang-language/reference/built-in-functions/struct/structeach.md)
* [StructEquals](/boxlang-language/reference/built-in-functions/struct/structequals.md)
* [StructEvery](/boxlang-language/reference/built-in-functions/struct/structevery.md)
* [StructFilter](/boxlang-language/reference/built-in-functions/struct/structfilter.md)
* [StructFind](/boxlang-language/reference/built-in-functions/struct/structfind.md)
* [StructFindKey](/boxlang-language/reference/built-in-functions/struct/structfindkey.md)
* [StructFindValue](/boxlang-language/reference/built-in-functions/struct/structfindvalue.md)
* [StructGet](/boxlang-language/reference/built-in-functions/struct/structget.md)
* [StructGetMetadata](/boxlang-language/reference/built-in-functions/struct/structgetmetadata.md)
* [StructInsert](/boxlang-language/reference/built-in-functions/struct/structinsert.md)
* [StructIsCaseSensitive](/boxlang-language/reference/built-in-functions/struct/structiscasesensitive.md)
* [StructIsOrdered](/boxlang-language/reference/built-in-functions/struct/structisordered.md)
* [StructKeyArray](/boxlang-language/reference/built-in-functions/struct/structkeyarray.md)
* [StructKeyExists](/boxlang-language/reference/built-in-functions/struct/structkeyexists.md)
* [StructKeyList](/boxlang-language/reference/built-in-functions/struct/structkeylist.md)
* [StructKeyTranslate](/boxlang-language/reference/built-in-functions/struct/structkeytranslate.md)
* [StructMap](/boxlang-language/reference/built-in-functions/struct/structmap.md)
* [StructNew](/boxlang-language/reference/built-in-functions/struct/structnew.md)
* [StructNone](/boxlang-language/reference/built-in-functions/struct/structnone.md)
* [StructReduce](/boxlang-language/reference/built-in-functions/struct/structreduce.md)
* [StructSome](/boxlang-language/reference/built-in-functions/struct/structsome.md)
* [StructSort](/boxlang-language/reference/built-in-functions/struct/structsort.md)
* [StructToQueryString](/boxlang-language/reference/built-in-functions/struct/structtoquerystring.md)
* [StructToSorted](/boxlang-language/reference/built-in-functions/struct/structtosorted.md)
* [StructUpdate](/boxlang-language/reference/built-in-functions/struct/structupdate.md)
* [StructValueArray](/boxlang-language/reference/built-in-functions/struct/structvaluearray.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structcopy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
