python - JSON dump breaks my dictionary when using certain characters -


dumping data file json.dump. data looks this:

{"hello": {"this": 1, "a": 1, "is": 1, "test": 1}} 

the code use achieve follows (worddict file, file.json):

with open(words, 'w') fp:     json.dump(worddict, fp) fp.close() 

i'd have data in format:

{ "hello": {     "a": 1,     "is": 1,     "test": 1,     "this": 1 } 

i changed code this:

with open(words, 'w') fp:     json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': ')) fp.close() 

and works, until try dump characters "Á", "É", "Ű"... these characters breaks worddict file, , when cat file looks this:

{ 

any idea why?

replace

    json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': ')) 

with

    json.dump(worddict, fp, sort_keys=true, indent=4, separators=(',', ': '), ensure_ascii=false) 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -