[Numpy-discussion] numpy array serialization with JSON

Simon Palmer simon.palmer at gmail.com
Tue Nov 11 15:41:37 EST 2008


"Does JSON have a representation for n-d arrays? In my little work with
it, it looked pretty lame for arrays of number, so I'd be surprised."
yes it does, thet are just treated as nested lists and the square bracket
notation is used.  JSON is far from perfect but for objects of basic types
it is about as efficient as you can get if you need a generalised human
readable form, it certainly beats verbose XML.

simplejson is actually a pretty good package, it's just a shame there's
nothing for numpy ndarrays.  If I end up writing one I'll contribute it back
either here or probably better to simplejson.



On Mon, Nov 10, 2008 at 5:58 PM, Christopher Barker
<Chris.Barker at noaa.gov>wrote:

> Simon Palmer wrote:
> > What, if any, header information from numarray gets put in the bytes by
> > tostring(), especially as I have n dimensions?
>
> none, you'd have to do that separately.
>
> > I am very likely to be deserializing into a Java Array object (or maybe
> > a double[]) and it is not clear to me how I would do that from the bytes
> > in the tostring() representation.
>
> If you're thinking JSON, then I think you'd want text, not binary. Maybe
> you can make use of the repr()?
>
> It wouldn't be hard to just right your own text renderer from scratch,
> unless you need C speed. Python being python, I'd tend to see what your
> Java (or Javascript) code can easily consume, then write the python code
> to generate that.
>
>
>
> -Chris
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081111/6f7338f1/attachment.html>


More information about the NumPy-Discussion mailing list