Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Schema: required field

Im trying to use json-schema validation at some project, and want to ask about the "required" field.

In current doc there is a specifiaction:

The value of this keyword MUST be an array. This array MUST have at least one element. Elements of this array MUST be strings, and MUST be unique.

But in another examples in the web, i can find something like:

"properties": {
    "foo": {
        "required": true
    }
}

What is a valid way to define required fields?

like image 522
Sergey Kamardin Avatar asked Jul 22 '13 12:07

Sergey Kamardin


People also ask

What is required in JSON Schema?

Required Properties The required keyword takes an array of zero or more strings. Each of these strings must be unique. In Draft 4, required must contain at least one string.

Is JSON Schema necessary?

It's often necessary for applications to validate JSON objects, to ensure that required properties are present and that additional validation constraints (such as a price never being less than one dollar) are met.

What does $Ref mean in JSON Schema?

In a JSON schema, a $ref keyword is a JSON Pointer to a schema, or a type or property in a schema. A JSON pointer takes the form of A # B in which: A is the relative path from the current schema to a target schema. If A is empty, the reference is to a type or property in the same schema, an in-schema reference.

What is JSON Schema validation?

JSON Schema validation asserts constraints on the structure of instance data. An instance location that satisfies all asserted constraints is then annotated with any keywords that contain non-assertion information, such as descriptive metadata and usage hints.


1 Answers

In version 3 of JSON Schema it was a boolean. In the latest version, 4, it is now an array of strings. The validator you are using may still be implementing the old specification.

like image 109
Daniel Coupal Avatar answered Oct 30 '22 20:10

Daniel Coupal