Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

anyjson - JSON library wrapper

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

Recent activity

Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

c828bf8 - Seems like json can't load StringIO to a unicode string
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

b9edcf7 - Reraise exceptions from original frame
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

93a0e86 - Use StringIO() and load to support buffer objects
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

4e162c4 - Renames serialize/deserialize to dumps/loads
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

c67742f - Now depends on simlejson if no other json libs installed
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

93b039e - Implementation.__str__ should be __repr__
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

9bacee8 - Doc regex didn't handle newlines
Ask Solem

Commits by Ask Solem were pushed to asksol/anyjson

34a9843 - Parses distmeta + adds trove classifiers
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.