1

My Json data looks like

{

"key1": "value1",

"key2": "value2",

"key3": "value3",

"iterKey": {

"key11": ["val11", "val12"],

"key21": ["val21"],

"key31": ["val31","val32"] }

}

In above Json data key1, key2 and key3 is fixed and its value is string. But iterKey is a Map which contains key value pair. The size and value of iterKey is not fixed. I want to write Json schema which will validate that all keys (key11, key21, key31 ..etc) are string and their value is list of strings.

(I dont know value of key11, key21 ..etc, it could be any value) Please help to write schema for this type of JSON data.

1 Answer 1

1

Use patternProperties instead of properties. Then, the keys are not objects but regular expressions. Use .*as regular expression to match everything.

{
  "type": "object",
  "properties": {
    "key1": {
      "type": "string"
    },
    ...
    "iterKey": {
      "type": "object",
      "patternProperties": {
        ".*": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

In the above example, how are you validating that value of key11, key21...etc is list of string?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.