[Django]-Django json single and double quotes?

5👍

update
remove the str() around list, simply simplejson.dumps(list). str() trans the list to a string, thus you got "[{'a': 'apple'}]" in client side.

Can you update the question to demo where simplejson encloses strings w/ single quotes?

django.utils.simplejson, normally, conforms w/ JSON specification and does not use single quotes to wrap things. If you mean

>>> from django.utils.simplejson import dumps
>>> dumps("Hello")
'"Hello"' # single quotes here
>>> repr(dumps("Hello"))
'\'"Hello"\'' # or here

They’re notations of Python, you don’t want to directly use them in JSON.parse (the first one is OK though).

👤okm

Leave a comment