Note
For extended and more in depth examples, refer to :ref:`examples`
The following example illustrates how this module works.
from json2py.models import *
class Example(NestedField):
hello = TextField(name = 'hi')
integer = IntegerField()
floating = FloatField()
class ExampleList(ListField):
__model__ = Example
dict_var = {'hi': 'world', 'integer': 1000, 'floating': 10.5, 'ignored': "you won't see me"}
list_var = [dict_var] * 3
myMappedList = ExampleList(list_var)
myMappedList[1].integer.value = 1234
print myMappedList.json_encode(indent = 4)
Should return something like:
[
{
"integer": 1000,
"floating": 10.5,
"hi": "world"
},
{
"integer": 1234,
"floating": 10.5,
"hi": "world"
},
{
"integer": 1000,
"floating": 10.5,
"hi": "world"
}
]
Note
The classes of this modules are intended to be reimplemented in order to make use of this module.
Models represent basic JSON data types. The usage of this models is intended to be subclassed in order to fully map the original JSON structure.
.. py:module:: json2py.models
.. autoclass:: BaseField :members:
.. autoclass:: TextField :members:
.. autoclass:: IntegerField :members:
.. autoclass:: FloatField :members:
.. autoclass:: BooleanField :members:
.. autoclass:: NestedField :members:
.. autoclass:: ListField :members:
.. autoclass:: DateField :members: