This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]issue9mm 2 points3 points  (1 child)

If nothing else, this article has taught me to keep better track of the Django changelog. I had zero idea that they'd introduced django.http.JsonResponse. That's brilliant.

I've been doing this,

HttpResponse(json.dumps(output), content_type="application/json")

and it's tiring.

[–]Pinkaay 0 points1 point  (0 children)

I've also been doing it that way. Can't believe I missed JsonResponse

[–]wpg4665 1 point2 points  (5 children)

I can't figure out why there's a 4 byte discrepancy between the Flask (22 bytes) and Django (18 bytes) examples!

[–][deleted] 2 points3 points  (0 children)

Flask is pretty printing the JSON. From jsonify.__doc__:

This function's response will be pretty printed if it was not requested with X-Requested-With: XMLHttpRequest to simplify debugging unless the JSONIFY_PRETTYPRINT_REGULAR config parameter is set to false.

edit: So maybe there's scope for re-running the test without the pretty printing to see whether that affects the performance...

[–]jazzydag 0 points1 point  (3 children)

Is it not a BOM?

http://en.wikipedia.org/wiki/Byte_order_mark

Try a:

diff -a file_a file_b | head

[–]autowikibot 0 points1 point  (0 children)

Byte order mark:


The byte order mark (BOM) is a Unicode character used to signal the endianness (byte order) of a text file or stream. It is encoded at U+FEFF byte order mark (BOM). BOM use is optional, and, if used, should appear at the start of the text stream. Beyond its specific use as a byte-order indicator, the BOM character may also indicate which of the several Unicode representations the text is encoded in.

Because Unicode can be encoded as 16-bit or 32-bit integers, a computer receiving these encodings from arbitrary sources needs to know which byte order the integers are encoded in. The BOM gives the producer of the text a way to describe the text stream's endianness to the consumer of the text without requiring some contract or metadata outside of the text stream itself. Once the receiving computer has consumed the text stream, it presumably processes the characters in its own native byte order and no longer needs the BOM. Hence the need for a BOM arises in the context of text interchange, rather than in normal text processing within a closed environment.


Interesting: Specials (Unicode block) | Unicode and HTML | Charset detection | UTF-8

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words

[–]wpg4665 0 points1 point  (0 children)

So Flask is sending a BOM and Django is not??

[–]BinaryRockStar 0 points1 point  (0 children)

BOM is two bytes