Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add more arguments to escape #781

Closed
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=(',', ': '))
self.write(resp)
Ben Darnell
Owner

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/escape.py
4 tornado/escape.py
View
@@ -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.
# http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped
- return json.dumps(value).replace("</", "<\\/")
+ return json.dumps(value, **kwargs).replace("</", "<\\/")
def json_decode(value):
Something went wrong with that request. Please try again.