Skip to main content

A library for dealing with JSON as python objects

Project description

[![Build Status](https://travis-ci.org/dannyroberts/jsonobject.png)](https://travis-ci.org/dannyroberts/jsonobject)

A python library for handling deeply nested JSON objects
as well-schema'd python objects.

It is supposed to be a simpler, more standalone, and faster version
of the DocumentSchema portion of `couchdbkit`

This is just in the hacking stages and the API is not stable.

##Example##

The code below defines a simple user model, and it's natural mapping to JSON.

```python
from jsonobject import *

class User(JsonObject):
username = StringProperty()
name = StringProperty()
active = BooleanProperty(default=False)
date_joined = DateTimeProperty()
tags = ListProperty(unicode)

```

Once it is defined, it can be used to wrap or produce deserialized JSON.

```python
>>> user1 = User(
name='John Doe',
username='jdoe',
date_joined=datetime.datetime.utcnow(),
tags=['generic', 'anonymous']
)
>>> user1.to_json()
{
'name': u'John Doe',
'username': u'jdoe',
'active': False,
'date_joined': '2013-08-05T02:46:58Z',
'tags': [u'generic', u'anonymous']
}
```

Notice that the datetime is converted to an ISO format string in JSON, but is a real datetime on the object:

```python
>>> user1.date_joined
datetime.datetime(2013, 8, 5, 2, 46, 58)
```

##Performance Comparison with Couchdbkit##
In order to do a direct comparison with couchdbkit, the test suite includes a large sample schema originally written with couchdbkit. It is easy to swap in jsonobject for couchdbkit and run the tests with each. Here are the results:
```
$ python -m unittest test.test_couchdbkit
....
----------------------------------------------------------------------
Ran 4 tests in 1.403s

OK
$ python -m unittest test.test_couchdbkit
....
----------------------------------------------------------------------
Ran 4 tests in 0.153s

OK


```

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

jsonobject-0.2.13.tar.gz (12.7 kB view details)

Uploaded Source

File details

Details for the file jsonobject-0.2.13.tar.gz.

File metadata

  • Download URL: jsonobject-0.2.13.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jsonobject-0.2.13.tar.gz
Algorithm Hash digest
SHA256 f6c43ca8ec174b0c1826f9815aebd495a8aa77cd1afa295e144b59aedbebd38f
MD5 1d1fc5c85998776ffa2b0cb2ce874fec
BLAKE2b-256 91e10f7275f50817cfa316afb19be9b6b5b0fa6b070f0afe1bec433f71b815a3

See more details on using hashes here.

Provenance

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