def json_unicode_to_utf8(data):
if isinstance(data, unicode):<EOL><INDENT>return data.encode('<STR_LIT:utf-8>')<EOL><DEDENT>elif isinstance(data, dict):<EOL><INDENT>newdict = {}<EOL>for key in data:<EOL><INDENT>newdict[json_unicode_to_utf8(<EOL>key)] = json_unicode_to_utf8(data[key])<EOL><DEDENT>return newdict<EOL><DEDENT>elif isinstance(data, list):<EOL><INDENT>return [json_unicode_to_utf8(elem) for elem in data]<EOL><DEDENT>else:<EOL><INDENT>return data<EOL><DEDENT>
Change all strings in a JSON structure to UTF-8.