Skip to content

Commit be4bb9f

Browse files
author
Cruz Monrreal
authored
Merge pull request #8177 from andrewleech/tools_json_python3
tools/utils: Fix issue with loading json files as ascii on python3 linux
2 parents 70252f8 + 41ff7b9 commit be4bb9f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from collections import OrderedDict
3131
import logging
3232
from intelhex import IntelHex
33+
import io
3334

3435
try:
3536
unicode
@@ -367,9 +368,9 @@ def json_file_to_dict(fname):
367368
fname - the name of the file to parse
368369
"""
369370
try:
370-
with open(fname, "r") as file_obj:
371-
return json.loads(file_obj.read().encode('ascii', 'ignore'),
372-
object_pairs_hook=OrderedDict)
371+
with io.open(fname, encoding='ascii',
372+
errors='ignore') as file_obj:
373+
return json.load(file_obj, object_pairs_hook=OrderedDict)
373374
except (ValueError, IOError):
374375
sys.stderr.write("Error parsing '%s':\n" % fname)
375376
raise

0 commit comments

Comments
 (0)