Registry / web-framework / flask-json

flask-json

JSON →
library0.4.0pypypi✓ verified 81d ago

Flask-JSON is a Flask extension that provides better JSON support, including automatic JSON serialization for object instances (via __json__() method), datetime objects, and arbitrary types. The current version is 0.4.0. Development appears to be in a maintenance state with no recent releases.

pip install flask-json
INSTALL
IMPORT
SIG · FLASK-JSON
F
flask-json
web-frameworkpythonv0.4.0
Install
2.2s avg
Import
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 22.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.000s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Jsonify
from flask_json import jsonify
from flask_json import Jsonify

Minimal Flask app using Flask-JSON to serialize a custom object.

from flask import Flask from flask_json import FlaskJSON, Jsonify app = Flask(__name__) json = FlaskJSON(app) class MyObject: def __init__(self, name): self.name = name def __json__(self): return {'name': self.name} @app.route('/') def index(): return Jsonify(data=MyObject('test')) if __name__ == '__main__': app.run()
Debug
Known issues
gotchaFlask-JSON overrides Flask's default JSON encoder globally. If you need custom encoding for different parts of your app, be careful as the global override might affect other extensions or libraries.
fix
Consider using flask.jsonify() with custom JSONEncoder or using Flask-JSON's Jsonify only in specific routes but be aware of the global override.
affects: all
gotchaThe __json__() method must be defined on custom objects to be serialized. If the method is missing, Flask-JSON will fall back to Flask's default encoder, which may not handle the object correctly.
fix
Ensure all custom classes that need serialization implement a __json__() method returning a JSON-serializable dict.
affects: all
deprecatedAs of Flask 2.3 and above, the `import flask.ext.json` path has been deprecated. Always use the direct import path: `from flask_json import ...`
fix
Use `from flask_json import FlaskJSON, Jsonify` instead of deprecated `flask.ext.json`.
affects: >=2.3
Upgrade
Version history
0.4.0latest on PyPI · released May 6, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
flask-json — pip install flask-json · libregistry