Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Jsonschema validate if the list contains one of the three strings

$
0
0

I have a json like this: {"mylist": ["a", "b", "c", "d", last_element]}

Here, last_element could be one of the following four strings - "w", "x", "y", "z"; but not multiple.

Examples:

{"mylist": ["a", "b", "c", "d", "x"] // <-- valid}{"mylist": ["a", "b", "c", "d", "y"] // <-- valid} {"mylist": ["a", "b", "c", "d", "x", "y"] // <-- not valid} 

How to write a jsonschema for this?

Current attempt:

{"type":"object","properties":{"mylist":{"type":"array","items":{"type":"string","enum":["a","b","c","d","w","x","y","z"            ]         },"minItems":1,"uniqueItems":true      }   },"required":["mylist"   ],"additionalProperties":false}

Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>