Flask extension for non-basic types' serialization to JSON via jsonplus lib.
Project description
Flask extension for non-basic types’ serialization to JSON via jsonplus lib.
Install
Install from PyPI:
pip install Flask-JSONPlus
Enable in your Flask app (probably your app/__init__.py):
from flask_jsonplus import FlaskJSONPlus
app = Flask(__name__)
app.config['JSONPLUS_EXACT'] = True
jsonplus = FlaskJSONPlus(app)
Usage
After you enable FlaskJSONPlus, Flask will start to use jsonplus internally for JSON (de-)serialization. For example, jsonify will properly serialize your rich data:
import datetime, fractions, decimal, collections
@app.route('/api/demo')
def api_demo():
Point = collections.namedtuple('Point', 'x y')
data = {
'third': fractions.Fraction(1, 3),
'dec': decimal.Decimal('0.1'),
'now': datetime.datetime.now(),
'set': set(range(3)),
'tuple': (3, 1, 4),
'namedtuple': Point(3, 4)
}
return jsonify(data)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-JSONPlus-0.0.4.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for Flask_JSONPlus-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71602a0052d96f87393337e074d2cd98503c7bd5f804c5330d3c0117ecfd26e |
|
MD5 | c486504b23ff9055f52df8907263a2ab |
|
BLAKE2b-256 | 27e5d46208877fe79c0d5a9258a3581ecf208341ad2a8096e80ea802bbb61b0e |