Skip to content

Specifying a square - dynamic minItems/maxItems for nested arrays? #730

Discussion options

You must be logged in to vote

So yes and no.

Generally there's no way to specify a size of one array based on the size of another because there's no way to query the size of an array.

If you know what sizes you want to support, this is proabably the brute-force-iest way with some consideration of not duplicating subschemas:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "array",
    "items": { /* item content */ }
  },
  "anyOf": [
    {
      "$ref": "#/$defs/size2",
      "items": { "$ref": "#/$defs/size2" }
    },
    {
      "$ref": "#/$defs/size3",
      "items": { "$ref": "#/$defs/size3" }
    },
    {
      "$ref": "#/$defs/size3",
      "items": { "$ref"

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@sneakers-the-rat
Comment options

@gregsdennis
Comment options

Answer selected by sneakers-the-rat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants