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) suggests this:
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?
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:
function doSomethingWithJson(obj:Dynamic) { /*...*/ }
function main() {
doSomethingWithJson([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.