This software presents a unified interface by encapsulating top-notch JSON implementation.
As for its functionality, you can use the serialize function to convert a Python object into a JSON string. Here's an example:
>>> import anyjson
>>> anyjson.serialize(["test", 1, {"foo": 3.141592}, "bar"])
'["test", 1, {"foo": 3.141592}, "bar"]'
For the reverse conversion, you can use the deserialize function as shown below:
>>> anyjson.deserialize("""["test", 1, {"foo": 3.141592}, "bar"]""")
['test', 1, {'foo': 3.1415920000000002}, 'bar']
Anyjson ensures uniform exceptions irrespective of the JSON implementation in use. In case of serialization of an incompatible object, it raises a type error:
>>> anyjson.serialize([object()])
Traceback (most recent call last): < snipped traceback >
TypeError: object is not JSON encodable
Likewise, when deserializing an invalid JSON string, it raises a value error:
>>> anyjson.deserialize("""['missing square brace!""")
Traceback (most recent call last):
ValueError: cannot parse JSON description.
Version 0.2.2: N/A