Skip to content

What about an isRequired keyword? #734

Closed
@sheinzle

Description

@sheinzle

We're working on client project with a huge flat input JSON file, with > 100 entries on the top level.

In such a setting, the required keyword becomes unmaintainable: when adding a new property or renaming a property, the required-list might get forgotten. Furthermore, as schema developer, it's not so clear on first sight which properties are actually required and which are not.

As I understand, there are already long discussions on how to support a require-all #659 , but what about turning around the require approach instead? Consider the following syntax:

{
    "properties": {
        "foo": {"type": "integer", "isRequired": true},
        "bar": {"type": "integer", "isRequired": true},
        "notRequired": {"type": "integer", "isRequired": false},
        "alsoNotRequired": {"type": "integer"}
        ... 100 more entries
    }
}

This way, we don't need the required keyword.

  • Each of the properties themselves can specify if they are required.
  • Renaming a property only needs one touchpoint, not modifying two source locations.
  • It is immediately clear, if a property is required or not.
  • And it should also work when combining schemas.

Disclaimer - I'm fairly new to the JSON schema, maybe I am missing a crucial bit.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions