Python json unicode - how to use eval with javascript

Really spent a lot of time looking for this. Please, help.

I am trying to add a multilingual feature to my web application infrastructure. For this, I cannot send non ascii characters as JSON. That's what I'm doing

  • Here is what I get from the database

    '\ xe0 \ xa4 \ xa4 \ xe0 \ xa5 \ x87 \ xe0 \ xa4 \ XB8 \ xe0 \ xa5 \ x8d \ xe0 \ xa4 \ xa4'

    which, when I type, gives me that good

    तेस्त

  • I am making a response object

    response = {'a': '\ xe0 \ xa4 \ xa4 \ xe0 \ xa5 \ x87 \ xe0 \ xa4 \ xb8 \ xe0 \ xa5 \ x8d \ xe0 \ xa4 \ xa4'}

  • Send an answer

    import json

    sys.stdout.write (json.dumps (answer))

  • This is what he prints.

    Returns u '{"a": "\ u0924 \ u0947 \ u0938 \ u094d \ u0924"}'

Any help pointers would be welcome

Thank!

Rushabh

+3
1

(. ensure_ascii json.dumps)?

sys.stdout.write(json.dumps(response, ensure_ascii=False))
{"a": "तेस्त"}
+4

Source: https://habr.com/ru/post/1727605/


All Articles