0

I have a frustrating problem. I have a Django web app. The model contains various CharField columns. When I convert these strings into JSON using json.dumps, the strings come out as Unicode like this:

"{'field': u'value'}"

and so forth. However, I need to pass this to Javascript, and the jQuery parser croaks on this format. What I am doing is surely a very common task, but I can't seem to find how to solve it.

Any help would be great.

2
  • Show the code that's creating the JSON. Commented Sep 9, 2010 at 6:20
  • That ain't json.dumps, that's repr. Commented Sep 9, 2010 at 9:14

1 Answer 1

4

Which Python Version are you using? Do you use the json module from the standard library?

At least under Python 2.6.4 I get the following results:

>>> import json
>>> e = {'field': u'value'}
>>> json.dumps(e)
'{"field": "value"}'
>>> e = {'field': u'vaäüßlue'}
>>> json.dumps(e)
'{"field": "va\\u00e4\\u00fc\\u00dflue"}'
>>> 

So either you're not really converting them into JSON or your code is wrong and does not use the converted value or if you don't use the module from the standard library, the one that you are actually using has some problems with unicode.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.