MCPcopy Create free account
hub / github.com/internetarchive/openlibrary / json_encode

Function json_encode

openlibrary/plugins/upstream/utils.py:295–301  ·  view source on GitHub ↗
(d, indent: int | str | None = None, sort_keys: bool = False)

Source from the content-addressed store, hash-verified

293
294@public
295def json_encode(d, indent: int | str | None = None, sort_keys: bool = False) -> str:
296 if isinstance(d, Nothing):
297 d = []
298
299 # Escape < and > so the output is safe inside <script> tags with unescaped $: output.
300 # </> are valid JSON unicode escapes; all parsers decode them correctly.
301 return json.dumps(d, indent=indent, sort_keys=sort_keys).replace("<", "\\u003c").replace(">", "\\u003e")
302
303
304@public

Callers

nothing calls this directly

Calls 1

dumpsMethod · 0.80

Tested by

no test coverage detected