JSON-encodes the given Python object.
(value: Any)
| 65 | # Please see https://github.com/tornadoweb/tornado/pull/706 |
| 66 | # before sending a pull request that adds **kwargs to this function. |
| 67 | def json_encode(value: Any) -> str: |
| 68 | """JSON-encodes the given Python object.""" |
| 69 | # JSON permits but does not require forward slashes to be escaped. |
| 70 | # This is useful when json data is emitted in a <script> tag |
| 71 | # in HTML, as it prevents </script> tags from prematurely terminating |
| 72 | # the javascript. Some json libraries do this escaping by default, |
| 73 | # although python's standard library does not, so we do it here. |
| 74 | # http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped |
| 75 | return json.dumps(value).replace("</", "<\\/") |
| 76 | |
| 77 | |
| 78 | def json_decode(value: Union[str, bytes]) -> Any: |