json - python turn u' into " -


i making lists of string data web, , want turn json, , getting , error need double quotes on json, how turn string web double quotes instead of u'?

here sample input

my_string = "test" my_array = [u'hi', u'hello'] 

and sample output

final = {"test":["hi", "hello"]} 

writing file this

my_file = open("test.json", "w") my_file.write(str(final)) my_file.close() 

thanks

you should use json library convert python dict objets json:

import json print(json.dumps({my_string:my_array}))  '{"test": ["hi", "hello"]}' 

Comments