The function sloppy_json_parse()
is a fork of the json_parse()
function
available at
http://www.json.org/json_parse.js. The
API for the two functions is the same, besides the format of the text that
they parse.
sloppy_json_parse()
parses a language similar to JSON, but with these
differences:
-
commas are optional
-
comments start with the '#' character and end with the end of the line
-
strings which match the regex
/[$_A-Z][$\w]*/i
don't need to be quoted, except that the strings "null", "true", and "false" must always be quoted. The regex is the syntax of JavaScript identifiers.
Re-inspired by CoffeeScript after thinking about it for a short while.
[1 2 3 dogs cats]
[1, 2, 3, "dogs", "cats"]
{x:y z:a}
{"x":"y", "z":"a"}
{
# some properties of the object
a: z # z is a string!
b: y # so is y
c: [1 2 3]
d: [ # d is an array
{
abc: true
def: false
} # end of this inner object
{
xyz: null
uvw: [101 202 303] # weird numbers
}
[4 5 6] # last element
]
# end of the properties
}
{
"a": "z",
"b": "y",
"c": [1, 2, 3],
"d": [
{
"abc": true,
"def": false
},
{
"xyz": null,
"uvw": [101, 202, 303]
},
[4, 5, 6]
]
}