Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


add more arguments to escape #781

wants to merge 1 commit into from

2 participants

项超 Ben Darnell

make escape support more parameters from json


if we want to return a json response which can be view formatly in browsers,we can code like this:

resp = tornado.escape.json_encode(response.body, indent=4, separators=(',', ': '))
Ben Darnell

See my response in #706

Ben Darnell bdarnell closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 8, 2013
  1. 项超
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 tornado/
4 tornado/
@@ -64,7 +64,7 @@ def xhtml_unescape(value):
return re.sub(r"&(#?)(\w+?);", _convert_entity, _unicode(value))
-def json_encode(value):
+def json_encode(value, **kwargs):
"""JSON-encodes the given Python object."""
# JSON permits but does not require forward slashes to be escaped.
# This is useful when json data is emitted in a <script> tag
@@ -72,7 +72,7 @@ def json_encode(value):
# the javscript. Some json libraries do this escaping by default,
# although python's standard library does not, so we do it here.
- return json.dumps(value).replace("</", "<\\/")
+ return json.dumps(value, **kwargs).replace("</", "<\\/")
def json_decode(value):
Something went wrong with that request. Please try again.