Ben Bangert committed 4e9d481

* jsonify now properly sets charset to utf-8.

Comments (0)

Files changed (3)

 1.1 (**tip**)
+* jsonify now properly sets charset to utf-8.
 * Add ability for jsonify to handle objects with a __json__ attribute using
   custom JSONEncoder class similar to TG2. Patch by Bob Farrell.
 * Added ability for __before__ to reference a callable function. Patch


     pylons = get_pylons(args)
-    pylons.response.headers['Content-Type'] = 'application/json'
+    pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'
     data = func(*args, **kwargs)
     if isinstance(data, (list, tuple)):
         msg = "JSON responses with Array envelopes are susceptible to " \
         warnings.warn(msg, Warning, 2)
     log.debug("Returning JSON wrapped action output")
-    return simplejson.dumps(data, cls=JSONEncoder)
+    return simplejson.dumps(data, cls=JSONEncoder, encoding='utf-8')
 def validate(schema=None, validators=None, form=None, variable_decode=False,


     def test_good_json(self):
         response = self.get_response(action='test_good_json')
         assert '{"fred": 42}' in response
+        assert response.header('Content-Type') == 'application/json; charset=utf-8'