Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Multidimensional array in Json

Moderators: larsivi kris

Posted: 04/30/09 22:57:49

Could anybody tell me how to save an array in Json like this, but then correct? (First time Tango user :))

int i; int[100] array; int[100][100][10] bigArray;

auto json = new Json!(char);

with (json) {

value = object (pair("i", value(i))); //ok value = object (pair("array", array(array)); //not ok value = object (pair("bigArray", array(bigAray)); // no clue :)

auto outfile = new File("data.dat");

json.print ((char[] s) {outfile.write(s);});

Author Message

Posted: 05/01/09 00:46:55 -- Modified: 05/01/09 00:47:10 by

the array call accepts a set of JsonValue instances, not D arrays. It does support multidimensional array-construction, but again, not via D arrays. Perhaps this could be an enhancement request?

Posted: 05/01/09 01:00:33

Yes please :D

But does that mean it now isn't possible to get a simple D array written inside a json array?

Posted: 05/01/09 01:51:43

a notably more efficient way is to emit the json text yourself, rather than wrapping each D array-element in a JsonValue first. Especially with the million element multi-dimensional array you indicated in the example :)

Posted: 05/01/09 11:48:52

You mean writing a function which translates the array to an char[][] and then parsing it? That sounds inefficient, you probably mean something else :D

(How long until a feature request gets attention ? :D )

Is reading(.parse) the array with Json efficient enough for this kind of array?

In actuality the array is an float[100][100][10] array

Posted: 05/01/09 15:13:41

Unless Kris decides to implement your feature request right now, you should create a ticket to keep it within reach of our minds :)