JSONY - Relaxed JSON with a little bit of YAML
Synopsis
require 'jsony'
data = JSONY.load jsony_string
Description
JSONY is a data language that is simlar to JSON, just more chill. All valid JSON is also valid JSONY (and represents the same thing when loaded), but JSONY lets you omit a lot of the syntax that makes JSON a pain to write.
API
JSONY has one method JSON.load
. You pass it a JSONY string and it returns the decoded Ruby data object.
Note: JSONY is basically hand-written format, so to serialize it back to disk you can just use the JSON dump serialization (for now), and it will round-trip safely.
JSONY Syntax
Here is some examples of JSONY followed by equivalent JSON:
Words don’t need quotes. A list of things is an array:
foo baz
[ "foo", "bar", "baz" ]
Strings with spaces can use single or double quotes:
'foo bar' # <= This is (a comment indicating) a string
# More commenting
"baz boom "
[ "foo bar ", "baz boom " ]
Top level hashes can either use ‘:’ separated pairs or use curlies. Sub-hashes require curlies.
foo: { bar baz }
num: -1.2e3
{ "foo": { "bar": "baz" }, "num": -1.2e3 }
Top level arrays can use ‘- ’ at the start of lines. Those arrays go the end of line. Lines can be continued using a trailing comma. Sub arrays require square brackets.
- array of 4 scalars
- array with [ sub
array { of
things }]
- array of 7 things on,
two lines
[
[ "array", "of", 4, "scalars" ],
[ "array", "with", [ "sub", "array" { "of", "things" } ] ],
[ "array", "of", 7, "things", on, "two", "lines" ]
]
More soon…
NOTE: You may want to look at the tests (especially test/decode.rb
) to see the full abilities of JSONY.
Status
*BEWARE!!!*
JSONY is mst’s idea, and ingy’s Pegex-based implementation. The language is just a baby, and will change a lot, or may go away entirely.
Development people are currently working on this in #jsony
in irc.freenode.net. Please drop by.
jsony.org/ coming soon.
Copyright
Copyright © 2012 Ingy döt Net. See LICENSE for further details.