1

I have a simple JSON schema that looks like so (and works)

{
    "cols": {
        "type": "array",
        "items": {
            "type": "string",
            "enum": [
                "id",
                "name",
                "age",
                "affiliation",
                ""
            ]
        },
        "additionalProperties": false
    }
}

I would like the enum to be the values prescribed above + a decoration so that any of the following would be allowed

"enum" = [
    "id",
    "lower(name)",
    "average(age)",
    "distinct(affiliation)",
    ""
]

In other words, for cols

  • cols=id would be valid but no further decoration would be allowed around id
  • cols=name and cols=lower(name) would be valid
  • cols=age and cols=average(age) would be valid
  • cols=affiliation and cols=distinct(affiliation) would be valid
  • cols='' empty string would be valid

Specifying the decorations as patterns would be great so that they would be case-insensitive. For example, cols=lower(name) and cols=LOWER(name) would both be ok.

1 Answer 1

2

You can change your enumerated list in enum to a list of patterns:

"items": [
  "type": "string",
  "anyOf": [
    { "pattern": "^cols\b...the rest of your pattern here...$" },
    { etc... }
  ]
]
Sign up to request clarification or add additional context in comments.

Comments

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.