python-jsonschema

handling infinity values in JSON

笑着哭i 提交于 2021-02-05 11:34:06
问题 I need at one place to have the support for infinity, -infinity and NaN values in my JSON. Now though JSON does have support for these values, but is there any support for specifying about them in the schema of the same JSON instance, I mean the RFC specification says that these values are not supported under "number" type. However, when I validated one such JSON instance having infinity value against a schema with the type "number", it produced no error! Can someone help me to figure out why

Is there a way to raise an error for any additional key present in JSON if I am using the if-else condition of JSON Schema?

烂漫一生 提交于 2020-05-15 07:59:05
问题 I have a use case where I want to check the keys present in JSON, depending on the value of a different key. Example JSON-1: { "key_name" : "value1", "foo" : "random_value1" } Example JSON-2: { "key_name" : "value2", "bar" : "random_value2" } As per these examples, Rule 1. If the value of "key_name" is "value1" then only "foo" key should be present in JSON. Rule 2. If the value of "key_name" is "value2", then only "bar" key should be present in JSON. I have written the following JSON Schema

JSON Schema conditional required if and only if a specific key exists in nested object

Deadly 提交于 2020-01-17 01:00:12
问题 My question for jsonschema is twofold: Given { "foo": {"ar": {"a": "r"}}, "bar": "" } How do I check if the key "ar" exists inside of "foo"? And only if "ar" exists inside of "foo", how do I make it so that "bar" must exists inside the given json? I have tried looking other SO answers or jsonschema docs, but they only seem to check if the key has a specific value rather than if the key just exists regardless of its value. And the jsonschema for nested objects only seem to check for the

How to set up local file references in python-jsonschema document?

99封情书 提交于 2020-01-15 07:28:20
问题 I have a set of jsonschema compliant documents. Some documents contain references to other documents (via the $ref attribute). I do not wish to host these documents such that they are accessible at an HTTP URI. As such, all references are relative. All documents live in a local folder structure. How can I make python-jsonschema understand to properly use my local file system to load referenced documents? For instance, if I have a document with filename defs.json containing some definitions.

Validating Heterogeneous Lists of Objects with JsonSchema and $ref

删除回忆录丶 提交于 2019-12-25 02:15:23
问题 I have seen answers to similar questions that do not quite match this particular case, so apologies if I missed a relevant answer. I have a heterogeneous array of objects that I would like to validate. These objects have the same format at the top level, but the child objects are quite different and can only be identified by the attributes present in each child. The problem maps to validating the following data, though I have more than two object types in the array: { "heterogeneous_array": [

json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes:

北战南征 提交于 2019-12-13 05:10:29
问题 Hi I am working with JSON in my file in Python: import json userData = '''[ { "userID" : "20", "devices" : { "360020000147343433313337" : "V33_03", "3f0026001747343438323536" : "Door_03", "170035001247343438323536" : "IR_06", "28004c000651353530373132" : "BED_17" } }, ]''' info = json.loads(userData) I get this error when I load it: json.decoder.JSONDecodeError: Expecting value: or sometimes when I add something: json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: