# How do I create Array\<Dynamic\> literals?

**URL:** <https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756>\
**Category:** Haxe\
**Created:** [January 22, 2026, 10:17pm UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756 "2026-01-22T22:17:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidgiven](https://community.haxe.org/user_avatar/community.haxe.org/davidgiven/32/1326_2.png) [@davidgiven](https://community.haxe.org/u/davidgiven)\
**Post date:** [January 22, 2026, 10:17pm UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756/1 "2026-01-22T22:17:56Z")

</div>

In haxe, `[1, 2, 3]` creates an array. All the members must be of the same type. If you want to create an array where the elements are of different types, you need to explicitly tell the compiler that it’s an `Array<Dynamic>`. The [example in the documentation]([https://haxe.org/manual/std-Array.html](https://haxe.org/manual/std-Array.html)) suggests this:

```haxe
var myExplicitArray: Array<Dynamic> = [10, "Sally", true];

```

But that defines a new variable. What do I do if I want to use the array, as a literal, in some other structure? Such as, in my case, creating a large, complex JSON structure?

Or, in other words, how do I do this:

```haxe
doSomethingWithJson([1, ["value" => 2], "three"]);

```

(As an aside, the same problem applies with mixed-type maps.)

(I also posted this to SO here, but it’s not getting any love: [https://stackoverflow.com/questions/79873319/how-do-i-represent-an-arraydynamic-literal-in-haxe](https://stackoverflow.com/questions/79873319/how-do-i-represent-an-arraydynamic-literal-in-haxe) Feel free to answer there if you want some cheap karma…)

---

<div class="post-metadata">

**Author:** ![kevin-kmetz](https://community.haxe.org/user_avatar/community.haxe.org/kevin-kmetz/32/2522_2.png) [@kevin-kmetz](https://community.haxe.org/u/kevin-kmetz)\
**Post date:** [January 22, 2026, 10:26pm UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756/2 "2026-01-22T22:26:10Z")

</div>

In your example, I believe you could do something like:

```haxe
doSomethingWithJson(([1, ["value" => 2], "three"] : Array<Dynamic>));

```

A colon can be used after a literal to specify its type in-place, though it often has to be surrounded by parentheses for whatever reason.

I’m fairly new to the language, so I’m sure someone with more experience here can offer more insight.

---

<div class="post-metadata">

**Author:** ![tobil4sk](https://community.haxe.org/user_avatar/community.haxe.org/tobil4sk/32/1458_2.png) [@tobil4sk](https://community.haxe.org/u/tobil4sk)\
**Post date:** [January 22, 2026, 10:48pm UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756/3 "2026-01-22T22:48:51Z")

</div>

> [@davidgiven](#):
>
> Or, in other words, how do I do this:
> 
> ```haxe
> doSomethingWithJson([1, ["value" => 2], "three"]);
> 
> ```

In most cases when dealing with json you are passing objects as `Dynamic` which works fine with arrays of mixed types, for example this signature works fine as-is with your original example:

```haxe
function doSomethingWithJson(obj:Dynamic) { /*...*/ }

function main() {
    doSomethingWithJson([1, ["value" => 2], "three"]);
}

```

> [@kevin-kmetz](#):
>
> A colon can be used after a literal to specify its type in-place, though it often has to be surrounded by parentheses for whatever reason.

The reason is that the parentheses are part of the syntax: `( expr : Type )`, see: [type check - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/expression-type-check.html)

---

<div class="post-metadata">

**Author:** ![davidgiven](https://community.haxe.org/user_avatar/community.haxe.org/davidgiven/32/1326_2.png) [@davidgiven](https://community.haxe.org/u/davidgiven)\
**Post date:** [January 22, 2026, 11:29pm UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756/4 "2026-01-22T23:29:21Z")

</div>

> [@tobil4sk](#):
>
> In most cases when dealing with json you are passing objects as `Dynamic` which works fine with arrays of mixed types, for example this signature works fine as-is with your original example:
> 
> ```haxe
> function doSomethingWithJson(obj:Dynamic) { /*...*/ }
> 
> function main() {
> doSomethingWithJson([1, ["value" => 2], "three"]);
> }
> 
> ```

That’s only because it’s a simple example, though. Consider this:

```haxe
		doSomethingWithJson([1 => [1, ["value" => 2], "three"]]);

```

Casting the array does work, although it’s a bit ugly. And I can avoid some of the issues by using JSON structure syntax, like `{"one": 1, "two": “two”}`, as that creates a structure rather than a map; JsonPrinter doesn’t seem to care. Is there a similar shortcut for mixed-type arrays? Having to cast everywhere isn’t great for complex literals intended to go to JSON APIs.

---

<div class="post-metadata">

**Author:** ![player\_03](https://community.haxe.org/user_avatar/community.haxe.org/player_03/32/821_2.png) [@player\_03](https://community.haxe.org/u/player_03)\
**Post date:** [January 24, 2026, 1:24am UTC](https://community.haxe.org/t/how-do-i-create-array-dynamic-literals/4756/5 "2026-01-24T01:24:45Z")

</div>

If the first element of the array is `Dynamic`, Haxe will infer the rest as `Dynamic` too. In most cases, you can save even more space by using `Any`.

```haxe
[1 => [(1:Any), ["value" => 2], "three"]]

```
