The rson project contains a parser that allows experimentation with variations on readable file formats, and defines a base RSON profile that is a strict superset of JSON (properly subclassed, the RSON parser passes the Python simplejson testsuite, which itself creates a superset of JSON).
RSON was born out of frustration with the size and speed of the available pure-Python YAML parsers at the time, and was designed with very similar goals to YAML – key to these formats is the use of indentation as syntax, removal of unnecessary syntactical elements such as quotes whenever possible, the ability to add comments, and the ability to use JSON as valid input.
The base RSON format definition was designed to be easily parseable from any language, but the Python parser itself is both flexible and fast, allowing for variant formats to be easily designed and tested. One such format is something that easily round-trips to XML and another format allows macros and include processing .
But the flexibility comes at a price. There is more code, and the learning curve for all the options is more steep than it would be if the parser was not that flexible, and the documentation – well, it would take a long time to do a decent job on properly documenting all the options, so that hasn’t happened yet.
rsonlite is a pared-down version of rson that primarily handles the semantics of the indentation, allowing client code to do higher-level parsing. Unlike JSON or base RSON, which distinguish between ‘true’, ‘false’, ‘null’, strings, and numbers, or simplejson, which adds ‘Nan’ and ‘Infinity’ to the mix, rsonlite divides the world up into container nodes and leaf nodes, and every leaf node is a string.
转载本站任何文章请注明：转载至神刀安全网，谢谢神刀安全网 » Rsonlite – Easy Way to Create Custom Indented Data File Formats in Python