microjson - A minimal, valid, pure-Python JSON parser/emitter.
Goal was to create something small enough to be embedded into standalone scripts, enabling them to talk to an API which returns JSON data, like Github's, without relying on external dependencies other than the Python standard library.
Github offers multiple encodings, but I prefer the ease of working with JSON over XML; YAML is nice too, though I wasn't interested in writing a YAML parser.
obj = microjson.from_json(json_data)
json_data = microjson.to_json(obj)
I typically write the standalone scripts with this pattern:
def main():
do_something()
if __name__ == "__main__":
main()
If and when I need to update microjson, I'll pull down the latest from Github and use a sed command to generate the final script:
% sed -e '/^@MICROJSON@$/ { <return>
r microjson.py <return>
d; }' myscript.in >myscript
If you use cat or some other method of embedding microjson.py, make sure the "if __name__ ..." line is at the end of the script.