Flask-JSON


NameFlask-JSON JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/skozlovf/flask-json
SummaryBetter JSON support for Flask
upload_time2023-05-06 07:45:52
maintainer
docs_urlhttps://pythonhosted.org/Flask-JSON/
authorSergey Kozlov
requires_python
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            Flask-JSON
==========

.. image:: https://github.com/skozlovf/flask-json/actions/workflows/test.yml/badge.svg?branch=master
   :target: https://github.com/skozlovf/flask-json/actions/workflows/test.yml

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:

.. code-block:: python

    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:

.. code-block:: json

    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"
    }

.. code-block:: json

    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 <http://flask-json.readthedocs.io>`_.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/skozlovf/flask-json",
    "name": "Flask-JSON",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/Flask-JSON/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Sergey Kozlov",
    "author_email": "skozlovf@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ba/4a/6046e195241772f4b6add3adcd4e820004c6151afc587d8c7d0d4ffeb473/Flask-JSON-0.4.0.tar.gz",
    "platform": "any",
    "description": "Flask-JSON\n==========\n\n.. image:: https://github.com/skozlovf/flask-json/actions/workflows/test.yml/badge.svg?branch=master\n   :target: https://github.com/skozlovf/flask-json/actions/workflows/test.yml\n\nFlask-JSON is a simple extension that adds better JSON support to Flask\napplication.\n\nFeatures:\n\n* Works on python 2.6, 2.7, 3.3+ and Flask 0.10+.\n* More ways to generate JSON responses (comparing to plain Flask).\n* Extended JSON encoding support.\n\nUsage\n-----\n\nHere is fast example:\n\n.. code-block:: python\n\n    from datetime import datetime\n    from flask import Flask\n    from flask_json import FlaskJSON, JsonError, json_response, as_json\n\n    app = Flask(__name__)\n    FlaskJSON(app)\n\n\n    @app.route('/get_time')\n    def get_time():\n        return json_response(time=datetime.utcnow())\n\n\n    @app.route('/get_time_and_value')\n    @as_json\n    def get_time_and_value():\n        return dict(time=datetime.utcnow(), value=12)\n\n\n    @app.route('/raise_error')\n    def raise_error():\n        raise JsonError(description='Example text.', code=123)\n\n\n    if __name__ == '__main__':\n        app.run()\n\nResponses:\n\n.. code-block:: json\n\n    GET /get_time HTTP/1.1\n\n    HTTP/1.0 200 OK\n    Content-Type: application/json\n    Content-Length: 60\n\n    {\n      \"status\": 200,\n      \"time\": \"2015-04-14T13:17:16.732000\"\n    }\n\n.. code-block:: json\n\n    GET /raise_error HTTP/1.1\n\n    HTTP/1.0 400 BAD REQUEST\n    Content-Type: application/json\n    Content-Length: 70\n\n    {\n      \"code\": 123,\n      \"description\": \"Example text.\",\n      \"status\": 400\n    }\n\nDocumentation\n-------------\n\nDocumentation is available on\n`Read the Docs <http://flask-json.readthedocs.io>`_.\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Better JSON support for Flask",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/skozlovf/flask-json"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ae873b3ae3ca23dd90b15faa1128c473c1cf16d42e9f95efc5e4a1b77bf22260",
                "md5": "19c1b53d9b5e3aa10abde1bafb7148b0",
                "sha256": "1c1b87a657daa2179fc19f1ffc78204a716c7c5139673dc5038772db4d9f1988"
            },
            "downloads": -1,
            "filename": "Flask_JSON-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "19c1b53d9b5e3aa10abde1bafb7148b0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8714,
            "upload_time": "2023-05-06T07:45:50",
            "upload_time_iso_8601": "2023-05-06T07:45:50.883523Z",
            "url": "https://files.pythonhosted.org/packages/ae/87/3b3ae3ca23dd90b15faa1128c473c1cf16d42e9f95efc5e4a1b77bf22260/Flask_JSON-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba4a6046e195241772f4b6add3adcd4e820004c6151afc587d8c7d0d4ffeb473",
                "md5": "b3691b9b735ea685f9cba2dea249758c",
                "sha256": "07945d66024f3b77694ce1db5d1fe83940f2aa3bcad8a608535686be67e4bc48"
            },
            "downloads": -1,
            "filename": "Flask-JSON-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b3691b9b735ea685f9cba2dea249758c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15899,
            "upload_time": "2023-05-06T07:45:52",
            "upload_time_iso_8601": "2023-05-06T07:45:52.873249Z",
            "url": "https://files.pythonhosted.org/packages/ba/4a/6046e195241772f4b6add3adcd4e820004c6151afc587d8c7d0d4ffeb473/Flask-JSON-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-06 07:45:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "skozlovf",
    "github_project": "flask-json",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-json"
}
        
Elapsed time: 0.07894s