Commit f2dc73bd authored by Samuel GAIST's avatar Samuel GAIST

[schema] Import simplejson as json to make it easy to swap

parent 7392340e
......@@ -41,7 +41,7 @@ import collections
import pkg_resources
import six
import simplejson
import simplejson as json
import jsonschema
......@@ -55,7 +55,7 @@ def maybe_load_json(s):
with open(s, "rt") as f:
return maybe_load_json(f)
else:
return simplejson.loads(s, object_pairs_hook=collections.OrderedDict)
return json.loads(s, object_pairs_hook=collections.OrderedDict)
# if it is a 'file-like' object
if hasattr(s, "read"):
......@@ -94,7 +94,7 @@ def load_schema(schema_name, version=1):
with open(fname, "rb") as f:
data = f.read().decode()
schema = simplejson.loads(data)
schema = json.loads(data)
basedir = os.path.realpath(os.path.dirname(fname))
resolver = jsonschema.RefResolver("file://" + basedir + "/", schema)
......@@ -118,7 +118,7 @@ def validate(schema_name, data):
try:
cleaned_data, error_list = validate('toolchain', '/to/my/file.json')
except simplejson.JSONDecodeError as e:
except json.JSONDecodeError as e:
print(e)
......@@ -133,12 +133,12 @@ def validate(schema_name, data):
If ``data`` is a string and represents a valid filesystem path, the
relevant file will be opened and read as with
:py:func:`simplejson.load``. Otherwise, it will be considered to be
:py:func:`json.load``. Otherwise, it will be considered to be
string containing a valid JSON structure that will be loaded as with
:py:func:`simplejson.loads`.
:py:func:`json.loads`.
Note that if the file is opened and read internally using
:py:func:`simplejson.load`, exceptions may be thrown by that subsystem,
:py:func:`json.load`, exceptions may be thrown by that subsystem,
concerning the file structure. Consult the manual page for
:py:mod:`simplejson` for details.
......@@ -157,7 +157,7 @@ def validate(schema_name, data):
try:
data = maybe_load_json(data)
except simplejson.JSONDecodeError as e:
except json.JSONDecodeError as e:
return data, ["invalid JSON code: %s" % str(e)]
# handles the schema version
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment