Skip to main content

Wraps the best available JSON implementation available in a common interface

Project description

Overview

Anyjson loads whichever is the fastest JSON module installed and provides a uniform API regardless of which JSON implementation is used.

Originally part of carrot (http://github.com/ask/carrot/)

Examples

To serialize a python object to a JSON string, call the serialize function:

>>> import anyjson
>>> anyjson.serialize(["test", 1, {"foo": 3.141592}, "bar"])
'["test", 1, {"foo": 3.141592}, "bar"]'

Conversion the other way is done with the deserialize call.

>>> anyjson.deserialize("""["test", 1, {"foo": 3.141592}, "bar"]""")
['test', 1, {'foo': 3.1415920000000002}, 'bar']

Regardless of the JSON implementation used, the exceptions will be the same. This means that trying to serialize something not compatible with JSON raises a TypeError:

>>> anyjson.serialize([object()])
Traceback (most recent call last):
  <snipped traceback>
TypeError: object is not JSON encodable

And deserializing a JSON string with invalid JSON raises a ValueError:

>>> anyjson.deserialize("""['missing square brace!""")
Traceback (most recent call last):
  <snipped traceback>
ValueError: cannot parse JSON description

Contact

The module is maintaned by Rune F. Halvorsen <runefh@gmail.com>. The project resides at http://bitbucket.org/runeh/anyjson . Bugs and feature requests can be submitted there. Patches are also very welcome.

Changelog

See CHANGELOG file

License

see the LICENSE file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anyjson-0.3.3.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file anyjson-0.3.3.tar.gz.

File metadata

  • Download URL: anyjson-0.3.3.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for anyjson-0.3.3.tar.gz
Algorithm Hash digest
SHA256 37812d863c9ad3e35c0734c42e0bf0320ce8c3bed82cd20ad54cb34d158157ba
MD5 2ea28d6ec311aeeebaf993cb3008b27c
BLAKE2b-256 c34dd4089e1a3dd25b46bebdb55a992b0797cff657b4477bc32ce28038fdecbc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page