The pecan.jsonify module includes support for JSON rule creation using generic functions.
Bases: json.encoder.JSONEncoder
Generic JSON encoder. Makes several attempts to correctly JSONify requested response objects.
Converts an object and returns a JSON-friendly structure.
Parameters: | obj – object or structure to be converted into a JSON-ifiable structure |
---|
Considers the following special cases in order:
returns the result of the call to __json__()
returns the object cast to str
returns the object cast to float
returns a copy of the object.__dict__ with internal SQLAlchemy parameters removed
Casts the iterable ResultProxy into a list of tuples containing the entire resultset data, returns the list in a dictionary along with the resultset “row” count.
Note
{‘count’: 5, ‘rows’: [(‘Ed Jones’,), (‘Pete Jones’,), (‘Wendy Williams’,), (‘Mary Contrary’,), (‘Fred Smith’,)]}
Casts the RowProxy cursor object into a dictionary, probably losing its ordered dictionary behavior in the process but making it JSON-friendly.
returns webob_dicts.mixed() dictionary, which is guaranteed to be JSON-friendly.