[Python Edinburgh] JSON mapping library - recommendations?

Mark Smith mark.smith at practicalpoetry.co.uk
Tue Jan 11 15:54:45 CET 2011


I could... but I'm trying not to :)

I think I found what I was looking for: Linaro-python-json
https://launchpad.net/linaro-python-json/

<https://launchpad.net/linaro-python-json/>From the docs:

>>> class Person(IComplexJSONType):
...     def __init__(self, name):
...         self.name = name
...     def to_json(self):
...         return {'name': self.name}

Let's make a person instance:
>>> joe = Person('Joe')
>>> joe.name
'Joe'

We can now serialize this object using json.dumps() or any other json
module API. The only requirement is to pass our generic pluggable
encoder class:
>>> json.dumps(joe, cls=PluggableJSONEncoder, class_hint=None)
'{"name": "Joe"}'



I might have a play with it at some point to see whether it is a net gain.
It's certainly pretty similar to what I was thinking. Thanks for your
suggestions, guys.

--Mark

On 11 January 2011 14:06, John Sutherland <john at sneeu.com> wrote:

> Surely you could knock something together rather quickly with
> simplejson, and the magic __dict__ attribute of objects?
>
> John.
>
>
> --
> sneeu.com
> "A computer shall not waste your time or require you to do more work than
> is
> strictly necessary" – Jef Raskin.
> _______________________________________________
> Edinburgh mailing list
> Edinburgh at python.org
> http://mail.python.org/mailman/listinfo/edinburgh
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edinburgh/attachments/20110111/7e209ffc/attachment.html>


More information about the Edinburgh mailing list