[dancer-users] Returning JSON Data

Robert Smith spamfree at wansecurity.com
Sat Sep 26 21:05:07 BST 2015


It seems that there is still a problem with Dancer2 serializing JSON output and double encoding UTF-8 data.

I’ve thoroughly read:

https://github.com/PerlDancer/Dancer2/issues/686


https://github.com/PerlDancer/Dancer2/pull/520

Setting the options in 520 results in: "Body must be bytes and should not contain wide characters (UTF-8 strings)” error

https://github.com/PerlDancer/Dancer2/pull/647


I guess that since #686 is still open that there is no work around for those of us who need to use serializer: JSON and have UTF-8 encoded data coming from our database?

-Robert


> On Sep 14, 2015, at 4:19 PM, Kadir Beyazlı <kadirbeyazli at gmail.com> wrote:
> 
> Hi Russel,
> 
> 
> 
> On Mon, Sep 14, 2015 at 2:19 AM, Russell Jenkins
> <russell.jenkins at strategicdata.com.au> wrote:
>> On 14/09/2015 3:56 am, Kadir Beyazlı wrote:
>> 
>> Now my only problem is encoding JSON data.
>> My data is Turkish, I was setting charset as follow to display correcty
>> 
>> print $q->header(-content_type => "application/json; charset='utf8');
>> 
>> How will I do it at Dancer2?
>> 
>> 
>> Hey Kadir.
>> 
>> You do no need to specify your JSON content as being UTF-8.
>> 
>> RFC4627 states:
>> "JSON text SHALL be encoded in Unicode. The default encoding is UTF-8"
>> and goes on to explain how to determine the encoding of the octet stream.
> [KB] I did not specify UTF-8, but my display problem for Turkish
> characters is still going on.
> I am returning JSON data from file myproject.pm and using JSON data at
> file report.js.
> My files (myproject.pm and report.js) character sets are also UTF-8.
> At old method, when I set content to UTF-8, it was solved
> 
> 
>> Furthermore, the IANA assignment for 'application/json' includes the
>> following note:
>> "No "charset" parameter is defined for this registration. Adding one really
>> has no effect on compliant recipients."
>> 
>> Hope that helps,
>> Russell.
>> 
>> 
>> _______________________________________________
>> dancer-users mailing list
>> dancer-users at dancer.pm
>> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>> 
> 
> 
> 
> -- 
> Kadir Beyazlı
> Computer Engineer
> GSM : +90 535 821 50 00
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users



More information about the dancer-users mailing list