> 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/list/listtoarray.md).

# ListToArray

Converts a delimited list to an array

## Method Signature

```
ListToArray(list=[string], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean])
```

### Arguments

| Argument                  | Type      | Required | Description                                                    | Default |
| ------------------------- | --------- | -------- | -------------------------------------------------------------- | ------- |
| `list`                    | `string`  | `true`   | string list to filter entries from                             |         |
| `delimiter`               | `string`  | `false`  | string the list delimiter                                      | `,`     |
| `includeEmptyFields`      | `boolean` | `false`  | boolean whether to include empty fields in the returned result | `false` |
| `multiCharacterDelimiter` | `boolean` | `false`  | boolean whether the delimiter is multi-character               | `false` |

## Examples

### Simple example for listToArray function

Uses the listToArray() function to retrieve a list as an array

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUCpKTdFJL0pNzdPJL0rMS09VsuZKTy1xLCpKrARK5wBVheSDeRpgjoKmNVdxfm6qV7C%2FH1AeRAWnFmUm5mRWpWoowHUCVZUXZZak%2BpeWFJSWaCjAtQAlAOB7KJE%3D)

```java
list = "red,green,orange";
getArray = listToArray( list );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

Result: \["red", "green", "orange"]

### Example for listToArray function with delimiter

Uses the listToArray() function with a semicolon delimiter to retrieve a list as an array

[Run Example](https://try.boxlang.io?code=eJzLySwuUbBVUErKr8hJzEu3LsgosM5KLEu0Li7MUbLmSk8tcSwqSqwEKskBqgzJB%2FM0wBwdBSVrJQVNa67i%2FNxUr2B%2FP6AiEBWcWpSZmJNZlaqhANcOVFVelFmS6l9aUlBaoqEA16JpDQAl4isI)

```java
list = "boxlang;php;java;sql";
getArray = listToArray( list, ";" );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

Result: \["boxlang", "php", "java", "sql"]

### Example for listToArray function with includeEmptyFields

If includeEmptyFields is true, empty value add in array elements

[Run Example](https://try.boxlang.io?code=eJzLySwuUbBVUErKr8hJzEu3LsgosLbOSixLtC4uzFGy5kpPLXEsKkqsBKrJASoNyQfzNMAcHQUlayUdhZKi0lQFTWuu4vzcVK9gfz%2BgUhAVnFqUmZiTWZWqoQA3BKiqvCizJNW%2FtKSgtERDAa4FKAEAhEctWQ%3D%3D)

```java
list = "boxlang;php;;java;sql";
getArray = listToArray( list, ";", true );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

Result: \["boxlang", "php", " " , "java", "sql"]

### Example for listToArray function with multiCharacterDelimiter

Uses the listToArray() function to retrieve a list as an array with multiCharacterDelimiter

[Run Example](https://try.boxlang.io/?code=eJw9jDEOwjAMRfeewsoUJN%2Bg6sDKQIdygQhcCDIk2A6oKIcndOj09fXf%2BxzVYAB3TnyZi8b0xHzLWI3U8B7eAau%2B2PXdlWwvEpYGc3NOaW1%2BLQgOq0OYAyshmBSCXd9petBhGo9N%2BcdEEgPHL3nYzhr1kWg0FsvFPGxKG343TDPk)

```java
list = "boxlang,php,|test,java,|sql";
getArray = listToArray( list, ",|", false, true );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

Result: \["boxlang,php", "test,java", "sql"]

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUCpKTdFJL0pNzdPJL0rMS09VsuZKTy1xLCpKrARK5wBVheSDeRpgjoKmNVdxfm6qV7C%2FH1AeRAWnFmUm5mRWpWoowHUCVZUXZZak%2BpeWFJSWaCjAtQAlAOB7KJE%3D)

```java
list = "red,green,orange";
getArray = listToArray( list );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUErOz0lJKy3OzM%2BzLsgosM5KLEu0Li7MUbLmSk8tcSwqSqwEqsoBKg7JB%2FM0wBwdBSVrJQVNa67i%2FNxUr2B%2FP6AiEBWcWpSZmJNZlaqhANcOVFVelFmS6l9aUlBaoqEA1wKUAAD5Lyxd)

```java
list = "boxlang;php;java;sql";
getArray = listToArray( list, ";" );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

[Run Example](https://try.boxlang.io/?code=eJw9jDEOwjAMRfeewsoUpN7AYmBloEO5QFRcMDIkOA4ITl%2FTodPX03%2F%2FC1eDPYQpy2VulfMTy60g3tM7YX1JwO5KdlBNX9fE7XNeKa7QQ8DQg2kj2GFX84OO43By9R8jKSfhH0XYTtz6KBsNzUqzCNvEiwU1ni6k)

```java
list = "boxlang;php;;java;sql";
getArray = listToArray( list, ";", true );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

[Run Example](https://try.boxlang.io/?code=eJw9jDEOwjAMRfeewsoUJN%2Bg6sDKQIdygQhcCDIk2A6oKIcndOj09fXf%2BxzVYAB3TnyZi8b0xHzLWI3U8B7eAau%2B2PXdlWwvEpYGc3NOaW1%2BLQgOq0OYAyshmBSCXd9petBhGo9N%2BcdEEgPHL3nYzhr1kWg0FsvFPGxKG343TDPk)

```java
list = "boxlang,php,|test,java,|sql";
getArray = listToArray( list, ",|", false, true );
someJSON = JSONSerialize( getArray );
writeOutput( someJSON );

```

## Related

* [GetToken](/boxlang-language/reference/built-in-functions/list/gettoken.md)
* [ListAppend](/boxlang-language/reference/built-in-functions/list/listappend.md)
* [ListAvg](/boxlang-language/reference/built-in-functions/list/listavg.md)
* [ListChangeDelims](/boxlang-language/reference/built-in-functions/list/listchangedelims.md)
* [ListCompact](/boxlang-language/reference/built-in-functions/list/listcompact.md)
* [ListContains](/boxlang-language/reference/built-in-functions/list/listcontains.md)
* [ListContainsNoCase](/boxlang-language/reference/built-in-functions/list/listcontainsnocase.md)
* [ListDeleteAt](/boxlang-language/reference/built-in-functions/list/listdeleteat.md)
* [ListEach](/boxlang-language/reference/built-in-functions/list/listeach.md)
* [ListEvery](/boxlang-language/reference/built-in-functions/list/listevery.md)
* [ListFilter](/boxlang-language/reference/built-in-functions/list/listfilter.md)
* [ListFind](/boxlang-language/reference/built-in-functions/list/listfind.md)
* [ListFindNoCase](/boxlang-language/reference/built-in-functions/list/listfindnocase.md)
* [ListFirst](/boxlang-language/reference/built-in-functions/list/listfirst.md)
* [ListGetAt](/boxlang-language/reference/built-in-functions/list/listgetat.md)
* [ListGetEndings](/boxlang-language/reference/built-in-functions/list/listgetendings.md)
* [ListIndexExists](/boxlang-language/reference/built-in-functions/list/listindexexists.md)
* [ListInsertAt](/boxlang-language/reference/built-in-functions/list/listinsertat.md)
* [ListItemTrim](/boxlang-language/reference/built-in-functions/list/listitemtrim.md)
* [ListLast](/boxlang-language/reference/built-in-functions/list/listlast.md)
* [ListLen](/boxlang-language/reference/built-in-functions/list/listlen.md)
* [ListMap](/boxlang-language/reference/built-in-functions/list/listmap.md)
* [ListNone](/boxlang-language/reference/built-in-functions/list/listnone.md)
* [ListPrepend](/boxlang-language/reference/built-in-functions/list/listprepend.md)
* [ListQualify](/boxlang-language/reference/built-in-functions/list/listqualify.md)
* [ListReduceRight](/boxlang-language/reference/built-in-functions/list/listreduceright.md)
* [ListRemoveDuplicates](/boxlang-language/reference/built-in-functions/list/listremoveduplicates.md)
* [ListRest](/boxlang-language/reference/built-in-functions/list/listrest.md)
* [ListSetAt](/boxlang-language/reference/built-in-functions/list/listsetat.md)
* [ListSome](/boxlang-language/reference/built-in-functions/list/listsome.md)
* [ListSort](/boxlang-language/reference/built-in-functions/list/listsort.md)
* [ListTrim](/boxlang-language/reference/built-in-functions/list/listtrim.md)
* [ListValueCount](/boxlang-language/reference/built-in-functions/list/listvaluecount.md)
* [ListValueCountNoCase](/boxlang-language/reference/built-in-functions/list/listvaluecountnocase.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/list/listtoarray.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.
