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

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

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