Commit 65c75bcd authored by Samuel GAIST's avatar Samuel GAIST

[schema] Error on duplicated key when loading JSON

parent a4232484
......@@ -37,13 +37,14 @@
import os
import collections
import pkg_resources
import six
import simplejson as json
import jsonschema
from beat.backend.python.utils import error_on_duplicate_key_hook
def maybe_load_json(s):
"""Maybe loads the JSON from a string or filename"""
......@@ -55,7 +56,7 @@ def maybe_load_json(s):
with open(s, "rt") as f:
return maybe_load_json(f)
else:
return json.loads(s, object_pairs_hook=collections.OrderedDict)
return json.loads(s, object_pairs_hook=error_on_duplicate_key_hook)
# if it is a 'file-like' object
if hasattr(s, "read"):
......@@ -163,6 +164,8 @@ def validate(schema_name, data):
data = maybe_load_json(data)
except json.JSONDecodeError as e:
return data, ["invalid JSON code: %s" % str(e)]
except RuntimeError as e:
return data, ["Invalid JSON: %s" % str(e)]
# handles the schema version
if schema_name != "dataformat":
......
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