Giter Site home page Giter Site logo

python-jsonable's Introduction

JSON-able data types

This library provides and abstract base class JSONable which enables easy definition of trivially JSON-able python objects.

  • Installation: pip install jsonable
Example:
>>> import jsonable
>>>
>>>
>>> class Fruit(jsonable.Type):
...     __slots__ = ('type', 'weight')
...
...     def initialize(self, type, weight):
...         self.type   = str(type)
...         self.weight = float(weight)
...
>>> class Pie(jsonable.Type):
...     __slots__ = ('fruit',)
...
...     def initialize(self, fruit):
...         self.fruit = [Fruit(f) for f in fruit]
...
...
>>> pie = Pie([Fruit('apple', 10.3), Fruit('cherry', 2)])
>>>
>>> doc = pie.to_json()
>>> doc
{'fruit': [{'weight': 10.3, 'type': 'apple'}, {'weight': 2.0, 'type': 'cherry'}]}
>>>
>>> pie == Pie(doc)
True

python-jsonable's People

Contributors

halfak avatar pyrox0 avatar

Stargazers

Timo Haanpää avatar Kazuki Moriyama avatar

Watchers

James Cloos avatar  avatar

python-jsonable's Issues

Shouldn't unicode be one of the JSON_TYPES?

Hello,

I'm trying to use JSONable to serialize my classes. Everything works fine except for unicode attributes.

Reading the code, I noticed that unicode is not one of the JSON_TYPES in jsonable.py resulting in an exception in _to_json method.

But according to Python documentation, it seems to be one of the "basic" types.

Am I wrong?

Thanks and regards,
Edouard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.