I can manually marshal into base64 which will be a lot more compact than something like the array bytestring hack. but then everyone consuming my format needs to come up with the same extension and needs to sniff values for encoding. and that makes me cry.
A JavaScript string is defined as a "sequence of zero or more 16-bit unsigned integer values." (http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf) and http://json.org/ [json.org] says "A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. [...]. A string is very much like a C or Java string."
Does that mean JSON "doesn't have native support for binary data"? Depends on your needs I guess (and whether you control the sending and/or receivin
Not related to JSON directly, but I've been reading the ajaxian the other day, and one guy managed to put the Prototype.js into a compressed PNG and read it back with the canvas methods. The whole 124K lib shrank to 30K:
http://ajaxian.com/archives/compression-using-canvas-and-png [ajaxian.com]
I didn't read the ECMAScript spec, but according to JSON.org then \u[four hex digits] is a valid way to specify a "character", so yes - I think so. It's still unicode, but you "munge" it to not have any high bits.
well (Score:1)
rjbs
Re: (Score:2)
Sorry to tell you this ... (Score:2)
Nope, it doesn't. I believe that's because JSON is valid JavaScript syntax and there's no "natural" way to represent binary in a simple string format.
What do you really mean by 'binary data'? (Score:1)
and http://json.org/ [json.org] says "A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. [...]. A string is very much like a C or Java string."
Does that mean JSON "doesn't have native support for binary data"? Depends on your needs I guess (and whether you control the sending and/or receivin
Re: (Score:1)
png & (Score:1)
JSON::XS makes it easy (Score:2)
$ perl -MJSON::XS -MFile::Slurp -e '$g=read_file("add.gif"); print JSON::XS->new->ascii(1)->encode({file=>$g})' > json
$ perl -MJSON::XS -MFile::Slurp -e '$g=read_file("json"); $d = decode_json($g); print $d->{file}' > gif
$ diff add.gif gif
$
-- ask bjoern hansen [askbjoernhansen.com], !try; do();
Re: (Score:2)
Re: (Score:2)
-- ask bjoern hansen [askbjoernhansen.com], !try; do();