Skip to main content

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 details)

Uploaded Source

Built Distribution

Flask_JSONPlus-0.0.4-py2.py3-none-any.whl (3.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file Flask-JSONPlus-0.0.4.tar.gz.

File metadata

File hashes

Hashes for Flask-JSONPlus-0.0.4.tar.gz
Algorithm Hash digest
SHA256 e6fffe7a41c5107f1e3f480a98860cf67e839edf4f44ad1babdb013a7ce4433f
MD5 8b542215f9daee7c0b91b4ee89bcc7ca
BLAKE2b-256 0aadb7033d87b3a33e2244278c8b7738e45033cd6079652d1985ad2012c32342

See more details on using hashes here.

File details

Details for the file Flask_JSONPlus-0.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Flask_JSONPlus-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e71602a0052d96f87393337e074d2cd98503c7bd5f804c5330d3c0117ecfd26e
MD5 c486504b23ff9055f52df8907263a2ab
BLAKE2b-256 27e5d46208877fe79c0d5a9258a3581ecf208341ad2a8096e80ea802bbb61b0e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page