Some devel news: you can now write gretl bundles as JSON using
bwrite() and read them back from JSON using bread(). In each case
gretl goes into JSON mode if the filename has extension ".json" or
".geojson".
The writer employs special JSON-object formats for matrices, series
and lists. Each format comprises a required "type" string, a
required "data" array, and for matrices and series required size
information.
matrix: { "type" : "gretl_matrix",
"rows" : integer,
"cols" : integer,
"data" : [ <vec of matrix> ] }
series: { "type" : "gretl_series",
"size" : integer <length of series>,
"data" : [ <series values, length size> ] }
list: { "type" : "gretl_list",
"data" : [ <integers> ] }
In the list case, for a list with n members the "data" array of
integers is of length n + 1, with the first value = n.
If a matrix or series includes missing values these are represented
by the string "NA" in place of a floating point value in the "data"
array. (Gretl's reader will handle that but AFAIK there's no truly
portable way of representing NAs in JSON.)
For export to third-party readers you can switch bwrite's mode for
matrices to something more generic: an m x n matrix is written as an
array of m arrays, each holding n doubles (so one sub-array per
row). This is the format used in GeoJSON files.
How to switch matrix mode? For now we've overloaded the optional
second argument to bwrite, making it into a "bitflags" integer
rather than a simple boolean. Giving a value of 1 has the original
meaning, namely write the bundle into the user's @dotdir, but adding
2 switches to generic matrix-writing -- and adding 4 switches to
pretty-printing the JSON. So for example, giving 6 for this option
will result in pretty-printed JSON with the generic matrix format.
Allin