MCPcopy
hub / github.com/fastapi/fastapi / _html_safe_json

Function _html_safe_json

fastapi/openapi/docs.py:9–19  ·  view source on GitHub ↗

Serialize a value to JSON with HTML special characters escaped. This prevents injection when the JSON is embedded inside a tag.

(value: Any)

Source from the content-addressed store, hash-verified

7
8
9def _html_safe_json(value: Any) -> str:
10 """Serialize a value to JSON with HTML special characters escaped.
11
12 This prevents injection when the JSON is embedded inside a <script> tag.
13 """
14 return (
15 json.dumps(value)
16 .replace("<", "\\u003c")
17 .replace(">", "\\u003e")
18 .replace("&", "\\u0026")
19 )
20
21
22swagger_ui_default_parameters: Annotated[

Callers 1

get_swagger_ui_htmlFunction · 0.85

Calls 1

dumpsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…