Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#23949 closed Cleanup/optimization (invalid)

Add charset to JsonResponse

Reported by: Torsten Bronger Owned by: nobody
Component: HTTP handling Version: 1.7
Severity: Normal Keywords:
Cc: bronger@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Please change the default content-type of JSON responses from "application/json" to "application/json; charset=ascii" or "application/json; charset=utf-8". The way Django generates the JSON, it's guaranteed to work with both values of charset. HTTP itself doesn't define a default charset for application/* types AFAIK.

Change History (6)

comment:1 Changed 9 years ago by Aymeric Augustin

Can you clarify why this change is needed?

comment:2 Changed 9 years ago by Torsten Bronger

Because I like don't like ambiguity, I overrode the content_type parameter in order to have a charset. But it would be nice if I needn't do this anymore in an upcoming Django version. It is a cosmetical problem I admit. The HTTP standard only states a default charset for text/* (namely 8859-1), so a client has to guess in case of application/* and in absence of charset, so I think it is good habit to make it explicit. Besides, there are no disadvantages, and it is a simple change.

comment:3 Changed 9 years ago by Tim Graham

Resolution: invalid
Status: newclosed

According to RFC 7159, "No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients."

See also the same report in flask which was closed as invalid.

comment:4 Changed 9 years ago by Tom Christie

Confirming tim's resolution. JSON responses in REST framework also don't include the charset, for the same reason.

comment:5 Changed 8 years ago by Serhiy

What do you think about defaulting to UTF-8? Right now it's ASCII, AFAIU. While the RFC clearly recommends UTF. Should I bother opening new ticket for this?

comment:6 Changed 8 years ago by Tim Graham

I believe it defaults to settings.DEFAULT_CHARSET which is 'utf-8' by default.

Note: See TracTickets for help on using tickets.
Back to Top