serializing to JSON that would retain hebrew charcters
I have the following use case:
from data I produce a json with data, part of it hebrew words. for example:
import json
j = {}
city =u'çéôä' #native unicode
j['results']= []
j['results'].append({'city':city}) #Also tried to city.encode('utf-8') and
other encodings
In order to produce a json file that doubles as my app db (a micro geoapp)
and as a file my users can edit and fix data directly I use the json lib
and:
to_save = json.dumps(j)
with open('test.json','wb') as f: #also tried with w instead of wb flag.
f.write(to_save)
f.close()
The problem is I get a unicode decoded json with u'çéôä' represented for
example as: u'\u05d7\u05d9\u05e4\u05d4'
most of the script and app don't have any problem reading the
Unicodestring but my USERS have one!, and since contributing to the
opensource project they need to edit the JSON directly, they can't figure
out the Hebrew text.
so, THE QUESTION: how should I write the json while opening it in another
editor would show Hebrew characters?
I'm not sure this is solvable because I suspect JSON is unicode all the
way and I can't use asccii in it, but not sure about that.
Thanks for the help
No comments:
Post a Comment