I’m working on a project that required a bit more from the JSON parser than the stock JSON parser with Python allowed for. After doing some hunting around, I came to the unfortunate conclusion that I’d probably need to write my own.
Thankfully, Python’s simpleparse module lived up to its billing (thanks in large part to JSON having such trivial syntax) Here’s the working BNF suitable for passing to simpleparse:
<ws> := [ tnr]*
>string_json< := string_single_quote / string_double_quote
key := string_json
array := "[", ws, ( value, (ws, ",", ws, value)* )?, ws, "]"member := key, ws, ":", ws, value
object := "{", ws, ( member, ( ws, ",", ws, member )* )?, ws, "}"true := "true"
false := "false"
null := "null"
>value< := false / null / true / object / array / float / int / string_json
>document< := ws, value, ws
This is also available in source code form here: jsonorder.py. jsonorder.py is part of a larger project, but it also works as a standalone library (albeit not a terribly useful one for most uses)
Very nicce blog you have here