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': 'John Doe',
'username': 'jdoe',
'active': False,
'date_joined': '2013-08-05T02:46:58Z',
'tags': ['generic', '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, 451286)
```
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': 'John Doe',
'username': 'jdoe',
'active': False,
'date_joined': '2013-08-05T02:46:58Z',
'tags': ['generic', '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, 451286)
```
Project details
Release history Release notifications | RSS feed
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.0.1.tar.gz
(3.7 kB
view details)
File details
Details for the file jsonobject-0.0.1.tar.gz
.
File metadata
- Download URL: jsonobject-0.0.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c1b47fdc57c54847e152db7f5852fb4385fd94c35e5fb9bb9d4b13d3f5c4100 |
|
MD5 | 623e6c33112a71bda8dbc22b301a1e17 |
|
BLAKE2b-256 | 0ef613c19808d45d70ab6b6f479fbf5b7bf6460408c102ccc8fcfc0667867edf |