Undocumented
Module | tag |
Tagged JSON ~~~~~~~~~~~ |
From __init__.py
:
Class | JSONDecoder |
The default JSON decoder. |
Class | JSONEncoder |
The default JSON encoder. Handles extra types compared to the built-in json.JSONEncoder . |
Function | dump |
Serialize an object to JSON written to a file object. |
Function | dumps |
Serialize an object to a string of JSON. |
Function | jsonify |
Serialize data to JSON and wrap it in a ~flask.Response with the :mimetype:`application/json` mimetype. |
Function | load |
Deserialize an object from JSON read from a file object. |
Function | loads |
Deserialize an object from a string of JSON. |
Variable | dataclasses |
Undocumented |
Function | _dump_arg_defaults |
Inject default arguments for dump functions. |
Function | _load_arg_defaults |
Inject default arguments for load functions. |
Function | htmlsafe_dump |
Serialize an object to JSON written to a file object, replacing HTML-unsafe characters with Unicode escapes. See htmlsafe_dumps and dumps . |
Function | htmlsafe_dumps |
Serialize an object to a string of JSON with dumps , then replace HTML-unsafe characters with Unicode escapes and mark the result safe with ~markupsafe.Markup . |
Parameters | |
kwargs:t.Dict[ | Undocumented |
app:t.Optional[ | Undocumented |
Parameters | |
kwargs:t.Dict[ | Undocumented |
app:t.Optional[ | Undocumented |
Serialize an object to a string of JSON.
Takes the same arguments as the built-in json.dumps
, with
some defaults from application configuration.
decimal.Decimal
is supported by converting to a string.Parameters | |
obj:t.Any | Object to serialize to JSON. |
app:t.Optional[ | Use this app's config instead of the active app context or defaults. |
**kwargs:t.Any | Extra arguments passed to json.dumps . |
Returns | |
str | Undocumented |
Serialize an object to JSON written to a file object.
Takes the same arguments as the built-in json.dump
, with
some defaults from application configuration.
Parameters | |
obj:t.Any | Object to serialize to JSON. |
fp:t.IO[ | File object to write JSON to. |
app:t.Optional[ | Use this app's config instead of the active app context or defaults. |
**kwargs:t.Any | Extra arguments passed to json.dump . |
Deserialize an object from a string of JSON.
Takes the same arguments as the built-in json.loads
, with
some defaults from application configuration.
Parameters | |
s:str | JSON string to deserialize. |
app:t.Optional[ | Use this app's config instead of the active app context or defaults. |
**kwargs:t.Any | Extra arguments passed to json.loads . |
Returns | |
t.Any | Undocumented |
Deserialize an object from JSON read from a file object.
Takes the same arguments as the built-in json.load
, with
some defaults from application configuration.
Parameters | |
fp:t.IO[ | File object to read JSON from. |
app:t.Optional[ | Use this app's config instead of the active app context or defaults. |
**kwargs:t.Any | Extra arguments passed to json.load . |
Returns | |
t.Any | Undocumented |
Serialize an object to a string of JSON with dumps
, then
replace HTML-unsafe characters with Unicode escapes and mark the
result safe with ~markupsafe.Markup
.
This is available in templates as the |tojson filter.
The returned string is safe to render in HTML documents and <script> tags. The exception is in HTML attributes that are double quoted; either use single quotes or the |forceescape filter.
jinja2.utils.htmlsafe_json_dumps
. The returned
value is marked safe by wrapping in ~markupsafe.Markup
.Parameters | |
obj:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
str | Undocumented |
htmlsafe_dumps
and dumps
.Parameters | |
obj:t.Any | Undocumented |
fp:t.IO[ | Undocumented |
**kwargs:t.Any | Undocumented |
Serialize data to JSON and wrap it in a ~flask.Response
with the :mimetype:`application/json` mimetype.
Uses dumps
to serialize the data, but args and
kwargs are treated as data rather than arguments to
json.dumps
.
from flask import jsonify @app.route("/users/me") def get_current_user(): return jsonify( username=g.user.username, email=g.user.email, id=g.user.id, )
Will return a JSON response like this:
{ "username": "admin", "email": "admin@localhost", "id": 42 }
The default output omits indents and spaces after separators. In
debug mode or if JSONIFY_PRETTYPRINT_REGULAR
is True,
the output will be formatted to be easier to read.
decimal.Decimal
is supported by converting to a string.Parameters | |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
Response | Undocumented |