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.

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask_JSONPlus-0.0.4-py2.py3-none-any.whl (3.4 kB) Copy SHA256 hash SHA256 Wheel 3.5
Flask-JSONPlus-0.0.4.tar.gz (2.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page