1

I'm using JSONField here for example:

sets = JSONField(null=True, blank=True)

However, when my app (Native not Python) writes to the API Django stores with extra character i.e. " becomes u', Why is this and how do I stop it?

Example returned data...

"sets": "{u'position': {u'y': u'-121-07', etc...

Prometheus
  • 32,405
  • 54
  • 166
  • 302
  • 2
    That is a unicode `u` – Padraic Cunningham May 18 '15 at 11:32
  • 2
    Read more about it here: http://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-in-python-and-what-are-raw-string-l – Joel Hinz May 18 '15 at 11:32
  • So ``"`` becomes ``u'`` but this additional character is given me issues parsing within my app. Are you saying that this shouldn't be an issue and the problem maybe with my native app? – Prometheus May 18 '15 at 11:36
  • 1
    You should show what this problem is and how you are doing the parsing. The point is that the output you are getting is the *deserialized* value, which is a Python dict and *not* JSON. – Daniel Roseman May 18 '15 at 11:46
  • I see that makes sense. So I could just convert it into a JSON object. thanks – Prometheus May 18 '15 at 11:56

1 Answers1

1

The u is added by Python 2.x as JSONField is using unicode strings.

They do no harm. However, if you don't want to see this, you might try Python 3.x since strings are u by default there.

See also Suppress the u'prefix indicating unicode' in python strings.

Community
  • 1
  • 1
SaeX
  • 17,240
  • 16
  • 77
  • 97