Skip to content

Instantly share code, notes, and snippets.

@bodiam
Created September 2, 2013 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodiam/6416328 to your computer and use it in GitHub Desktop.
Save bodiam/6416328 to your computer and use it in GitHub Desktop.
Simple Python object to JSON mapping
import json
class Light:
def __init__(self, id, name):
self.id = id
self.name = name
lights = [Light("1", "bedroom"),Light("2","kitchen")]
response = json.dumps([p.__dict__ for p in lights])
print response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment