> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/struct/structcopy.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
