2 ms·
Alternatively, you could use your "native" language and encode the data. I do that a lot, like so (Python): >>> import simplejson >>> v = ["My Values", {"t
by toxik 18y ago
Alternatively, you could use your "native" language and encode the data. I do that a lot, like so (Python):
>>> import simplejson
>>> v = ["My Values", {"type": 123, "Megahertz": 123.456}]
>>> print simplejson.dumps(v)
["My Values", {"Megahertz": 123.456, "type": 123}]
Heck, you could even do this:
>>> while True: print simplejson.dumps(input("JSON> "))
...
JSON> ["Hello", "World", [123, 321]]
["Hello", "World", [123, 321]]
JSON> [True, False, None]
[true, false, null]
- SwellJoe 18y agoIn the real world, I would think all JSON would be produced by code (there are easier to read/write formats for human generated data, like YAML or key=value or INI style config files, for which there are numerous parsers in every language I can think of). Perl has JSON::XS (my favorite) and the compatible pure-Perl JSON::PP, as well a few other options of varying degrees of quality and performance. use JSON::XS; my $json_reply = JSON::XS->new; print $json_reply->encode(["Hello", "World", [123, 321]]); We use map and grep extensively to produce the JSON to build our GUI elements, and it works like magic. I'm sure Ruby and PHP have similar libraries.