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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Flask-JSONPlus-0.0.4.tar.gz.
File metadata
- Download URL: Flask-JSONPlus-0.0.4.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6fffe7a41c5107f1e3f480a98860cf67e839edf4f44ad1babdb013a7ce4433f
|
|
| MD5 |
8b542215f9daee7c0b91b4ee89bcc7ca
|
|
| BLAKE2b-256 |
0aadb7033d87b3a33e2244278c8b7738e45033cd6079652d1985ad2012c32342
|
File details
Details for the file Flask_JSONPlus-0.0.4-py2.py3-none-any.whl.
File metadata
- Download URL: Flask_JSONPlus-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e71602a0052d96f87393337e074d2cd98503c7bd5f804c5330d3c0117ecfd26e
|
|
| MD5 |
c486504b23ff9055f52df8907263a2ab
|
|
| BLAKE2b-256 |
27e5d46208877fe79c0d5a9258a3581ecf208341ad2a8096e80ea802bbb61b0e
|