# StructAppend

Appends the contents of a second struct to the first struct either with or without overwrite

## Method Signature

```
StructAppend(struct1=[structloose], struct2=[structloose], overwrite=[boolean])
```

### Arguments

| Argument    | Type      | Required | Description                                                                                              | Default |
| ----------- | --------- | -------- | -------------------------------------------------------------------------------------------------------- | ------- |
| `struct1`   | `struct`  | `true`   | <p>The target struct which will be the recipient of the<br>appending</p>                                 |         |
| `struct2`   | `struct`  | `true`   | The struct containing the values to be appended                                                          |         |
| `overwrite` | `boolean` | `false`  | <p>Default true. Whether to overwrite existing values found<br>in struct1 from the values in struct2</p> | `true`  |

## Examples

### Append options to config struct (without overwrite flag)

[Run Example](https://try.boxlang.io/?code=eJxLzs9Ly0xXsFWoVuDidFSwUjDQ4eJ0AtFctdZc%2BQUlmfl5xSBpiKghUNYZRINki0uKSpNLHAsKUvNSNBSSwSbpKED16CikJeYUpypoWnOVF2WWpPqXlhSUlmgoeAX7%2BwWnFmUm5mRWpcJ0KWiC1AEAiAUo9A%3D%3D)

```java
config = { 
	A : 0,
	B : 0
};
options = {
	B : 1,
	C : 1
};
structAppend( config, options, false );
writeOutput( JSONSerialize( config ) );

```

Result: {"A":0,"B":0,"C":1}

### Append options to config struct (same, but using member function)

[Run Example](https://try.boxlang.io/?code=eJxLzs9Ly0xXsFWoVuDidFSwUjDQ4eJ0AtFctdZc%2BQUlmfl5xSBpiKghUNYZRINkk8F69RILClLzUjQUoIp1FNISc4pTFTStucqLMktS%2FUtLCkpLNBS8gv39glOLMhNzMqtSNRQgmhU0QeoAWzomUQ%3D%3D)

```java
config = { 
	A : 0,
	B : 0
};
options = {
	B : 1,
	C : 1
};
config.append( options, false );
writeOutput( JSONSerialize( config ) );

```

Result: {"A":0,"B":0,"C":1}

### Append options to config struct (with overwrite flag)

[Run Example](https://try.boxlang.io/?code=eJxLzs9Ly0xXsFWoVuDidFSwUjDQ4eJ0AtFctdZc%2BQUlmfl5xSBpiKghUNYZRINki0uKSpNLHAsKUvNSNBSSwSbpKMD0aFpzlRdllqT6l5YUlJZoKHgF%2B%2FsFpxZlJuZkVqXClCtogtQBAGzxJp0%3D)

```java
config = { 
	A : 0,
	B : 0
};
options = {
	B : 1,
	C : 1
};
structAppend( config, options );
writeOutput( JSONSerialize( config ) );

```

Result: {"A":0,"B":1,"C":1}

### Creating a request context from form and url scopes

Demonstrates how to construct a Request Context (rc) that combines the values of the form and url scopes

[Run Example](https://try.boxlang.io/?code=eJwrSlawVaiuteYqLikqTS5xLChIzUvRUChK1lFIyy%2FKVdDEJlNalAOSKC%2FKLEn1Ly0pKC3RUPAK9vcLTi3KTMzJrEoFKVPQBKkBABt3H1k%3D)

```java
rc = {};
structAppend( rc, form );
structAppend( rc, url );
writeOutput( JSONSerialize( rc ) );

```

### Polyfill for earlier versions

In older Boxlang version where this function is not supported yet, you can fall back to a native java method to achieve the same behavior except that it does not have the `overwriteFlag`.

[Run Example](https://try.boxlang.io/?code=eJxLzs9Ly0xXsFWoVuDidFSwUjDQ4eJ0AtFctdZc%2BQUlmfl5xSBpiKghUNYZRINkk8F69QpKSxxzcjQUYIo1rbnKizJLUv1LS4BSGgpewf5%2BwalFmYk5mVWpGgoQXQqaIHUAUXgj9A%3D%3D)

```java
config = { 
	A : 0,
	B : 0
};
options = {
	B : 1,
	C : 1
};
config.putAll( options );
writeOutput( JSONSerialize( config ) );

```

Result: {"A":0,"B":0,"C":1}

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxlj80KwjAQhM%2FmKYacKhR6V3ooFcSTQgXPa7LQYpuUNLUH8d3tn1bxtrMz2XxDpqiobBDjAbFKjxdsICtrZShWp8N%2BULYwNymeWxFFyHLbQbXOsfGg6a3YtVUdoKQrl7FMf00Z4k4unhXW45XUMXkGwXA3B0U%2FJuM0oPQkyXkkYdu9%2F07qmo2GzxlL2NsPRuZdq%2FyUCt7b8Cu7Xiosbi8Ko8pWcwNF%2FrdMMmN3hc8HF6Q16%2F9OL2AAaSU%3D)

```java
animals = { 
	COW : "moo",
	PIG : "oink"
};
// Show current animals
Dump( label="Current animals", var=animals );
// Create a new animal
newAnimal = {
	CAT : "meow"
};
// Append the newAnimal to animals
StructAppend( animals, newAnimal );
// Show animals, now includes cat
Dump( label="Animals with cat added", var=animals );

```

## Related

* [StructClear](/boxlang-language/reference/built-in-functions/struct/structclear.md)
* [StructCopy](/boxlang-language/reference/built-in-functions/struct/structcopy.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/structappend.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.
