Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Easily json dump types and classes

Project Description

[![Build Status](](


pip install moarjson

Basic usage

import moarjson as json

from datetime import datetime

json.dumps( # Fails

# Tell json to convert datetime objects to str first
json.register(datetime, str)

json.dumps( # Success

moarjson keeps track of all the types you want to encode to json.

import moarjson as json

from datetime import datetime

# Also available as decorator
def convert_datetime(obj):
return obj.strftime(format='%Y-%m-%d %H:%M')

# OR with lambda
json.register(datetime, lambda x: x.strftime(format='%Y-%m-%d %H:%M'))

Django models

Django user model field:

from django.contrib.auth.models import User

def convert_user(user):
return {
'username': user.username

def user_view(request):
# Json encoded user object
json_dump = json.dumps(User.objects.get(pk=1))

return HttpResponse(json_dump, content_type='application/json')

User.objects.all() is an iterable, so register iterables that first.
Convert any iterable to a list::

import collections
json.register(collections.Iterable, list)

def user_list_view(request):
# List of users
json_dump = json.dumps(User.objects.all())

return HttpResponse(json_dump, content_type='application/json')


### Code validation

The code is valid if it passes **flake8**.
Imports are sorted with **isort**.

### Testing

For testing **py.test** is used.
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
moarjson-0.3.4-py2.py3-none-any.whl (4.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Feb 16, 2014
moarjson-0.3.4.tar.gz (2.9 kB) Copy SHA256 Checksum SHA256 Source Feb 16, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting