JSONSchema how to define a schema for a dynamic object

I have a JSON response that I'm trying to create JSONSchema for

{
    "gauges": {
        "foo": {
            "value": 1234
        },
        "bar": {
            "value": 12.44
        }
    }
}

It is important to know that objects in an associative array are gaugesdynamically generated, so for many there may be zero. Each object in gaugeswill always have a property valueand will always be a number.

So each one is valid

Example 1

{
    "gauges": {
        "foo": {
            "value": 1234
        }
    }
}

Example 2

{
    "gauges": {
        "dave": {
            "value": 0.44
        },
        "tommy": {
            "value": 12
        },
        "steve": {
            "value": 99999
        }
    }
}

Example 3

{
    "gauges": {}
}

I looked at the specification, and if it was an array, I know what I can use anyOf, but I'm not sure how to do it or if it is possible.

NB I can not change the JSON format

+4
source share
1 answer

, , , .

, , , " "

{
"type": "object",
  "properties": {
    "gauges": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
           "value": {"type": "number"}
        }
      } 
    }
  }
}

"gauges" , "Properties" , .

.. java Map<String,Value> , . ( , )

JSON Map < String, Integer > ?

+3

Source: https://habr.com/ru/post/1674725/


All Articles