I came across this section in the docs :
RequestHandler.write(chunk)
Writes the given chunk to the output buffer.
To write the output to the network, use the flush() method below.
If the given chunk is a dictionary, we write it as JSON and set the Content-Type of the response to be application/json. (if you want to send JSON as a different Content-Type, call set_header after calling write()).
Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary. More details at http://haacked.com/archive/2009/06/25/json-hijacking.aspx/ and https://github.com/facebook/tornado/issues/1009
So I have a few questions related to this:
- What does it mean by this?
If the given chunk is a dictionary, we write it as JSON.
- What does it mean by this?
Note that lists are not converted to JSON because of a potential cross-site security vulnerability.
- What does it mean by this? And here, what does it mean by JSON output? And why to wrap it in a dictionary?
All JSON output should be wrapped in a dictionary.
This has two subparts :
a. What is the best way to send JSON responses from Tornado to client?
b. What is a better way to send responses? If not JSON, then what is? And if it JSON, then just mention the answer to subpart (a).
Please try to answer all the parts and their subparts in numbered manner so that I can understand them properly.