5

I am looking at this:

https://json-schema.org/understanding-json-schema/reference/type.html

I have an object with a function property, but I don't want to set additionalProperties to true. So I want do something like:

      "properties": {
        "getHostNameSync": {
          "type": "any",   // << any
          "required": false
        }
      }

but it says my schema definition is invalid. Is there a way to include functions properties?

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817

1 Answers1

13

With JSON Schema, you don't have to specify things. The syntax is declarative and adds restrictions. So if you don't want a restriction on the type of value that's allowed, don't use the type keyword.

  "properties": {
    "getHostNameSync": {}
  }

This will allow the getHostNameSync property to be literally anything since no restrictions have been declared.

NOTE If you're using draft 6 or later, you can use true instead of {} and get the same effect.

gregsdennis
  • 7,218
  • 3
  • 38
  • 71