Skip to main content

Better JSON support for Flask

Project description

https://travis-ci.org/skozlovf/flask-json.png?branch=master Documentation Status

Flask-JSON is a simple extension that adds better JSON support to Flask application.

Features:

  • Works on python 2.6, 2.7, 3.3+ and Flask 0.10+.

  • More ways to generate JSON responses (comparing to plain Flask).

  • Extended JSON encoding support.

Usage

Here is fast example:

from datetime import datetime
from flask import Flask
from flask_json import FlaskJSON, JsonError, json_response, as_json

app = Flask(__name__)
FlaskJSON(app)


@app.route('/get_time')
def get_time():
    return json_response(time=datetime.utcnow())


@app.route('/get_time_and_value')
@as_json
def get_time_and_value():
    return dict(time=datetime.utcnow(), value=12)


@app.route('/raise_error')
def raise_error():
    raise JsonError(description='Example text.', code=123)


if __name__ == '__main__':
    app.run()

Responses:

GET /get_time HTTP/1.1

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 60

{
  "status": 200,
  "time": "2015-04-14T13:17:16.732000"
}
GET /raise_error HTTP/1.1

HTTP/1.0 400 BAD REQUEST
Content-Type: application/json
Content-Length: 70

{
  "code": 123,
  "description": "Example text.",
  "status": 400
}

Documentation

Documentation is available on Read the Docs.

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-JSON-0.1.1.zip (11.0 kB view details)

Uploaded Source

File details

Details for the file Flask-JSON-0.1.1.zip.

File metadata

  • Download URL: Flask-JSON-0.1.1.zip
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Flask-JSON-0.1.1.zip
Algorithm Hash digest
SHA256 8ab07a885181de867cc513f58e534cd5506ea6e3abdcb1d75ae61266980ddb03
MD5 fb009429fc6e1c25d0a21af8a2948972
BLAKE2b-256 da9d38892b13c8c088b93aca0b6c5e1e1f95184e651af3954455d165cabc5093

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