{"id":23746,"library":"flask-json","title":"Flask-JSON","description":"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.","status":"maintenance","version":"0.4.0","language":"python","source_language":"en","source_url":"https://github.com/skozlovf/flask-json","tags":["flask","json","serialization","extension"],"install":[{"cmd":"pip install flask-json","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Correct import for the Jsonify class.","wrong":"","symbol":"Jsonify","correct":"from flask_json import Jsonify"},{"note":"Correct import for the FlaskJSON extension class.","wrong":"","symbol":"FlaskJSON","correct":"from flask_json import FlaskJSON"}],"quickstart":{"code":"from flask import Flask\nfrom flask_json import FlaskJSON, Jsonify\n\napp = Flask(__name__)\njson = FlaskJSON(app)\n\nclass MyObject:\n    def __init__(self, name):\n        self.name = name\n    def __json__(self):\n        return {'name': self.name}\n\n@app.route('/')\ndef index():\n    return Jsonify(data=MyObject('test'))\n\nif __name__ == '__main__':\n    app.run()","lang":"python","description":"Minimal Flask app using Flask-JSON to serialize a custom object."},"warnings":[{"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.","message":"Flask-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.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure all custom classes that need serialization implement a __json__() method returning a JSON-serializable dict.","message":"The __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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `from flask_json import FlaskJSON, Jsonify` instead of deprecated `flask.ext.json`.","message":"As 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 ...`","severity":"deprecated","affected_versions":">=2.3"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install flask-json with pip and use direct import: `from flask_json import Jsonify`","cause":"Using the deprecated flask.ext.json import path or the extension is not installed.","error":"ImportError: cannot import name 'Jsonify' from 'flask.ext.json'"},{"fix":"Add a __json__() method to your class that returns a dict. Also ensure you initialized FlaskJSON(app).","cause":"The object does not have a __json__() method, or Flask-JSON is not initialized properly.","error":"TypeError: Object of type MyClass is not JSON serializable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}