Monday, September 29, 2014

Python nested classes json encoder


Json pickle will do the trick : http://jsonpickle.github.io/

## import lib
import jsonpickle

## create class
class Thing(object):
    def __init__(self, name):
        self.name = name

## create class instance
obj = Thing('Awesome')

## from obj to json string
frozen = jsonpickle.encode(obj)

## from json string to obj
thawed = jsonpickle.decode(frozen)