You have defined your schema correctly, except that it doesn't match the data you say you are validating. If you change the property names to match the schema, you still have one issue. If you want to allow "toll" and "message" to be null, you can do the following.

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "loc": {
        "type": "string"
      },
      "toll": {
        "type": ["string", "null"]
      },
      "message": {
        "type": ["string", "null"]
      }
    },
    "required": [
      "loc"
    ]
  }
}

However, that isn't related to the error message you are getting. That message means that data you are validating is not an array. The example data you posted should not result in this error. Are you running the validator on some data other than what is posted in the question?

Answer from Jason Desrosiers on Stack Overflow
🌐
JSON Schema
json-schema.org › learn › miscellaneous-examples
JSON Schema - Miscellaneous Examples
The schema below represents a complex object with various properties including name, age, address, and hobbies. The address property is an object with nested properties, and the hobbies property is an array of strings.
🌐
Json-schema
tour.json-schema.org › content › 01-Getting-Started › 06-Array-of-Objects
Array of Objects: Getting Started | A Tour of JSON Schema
Each object in the array will have two properties name and level. Both name and level are strings. 1{ 2 "name": "John Doe", 3 "age": 25, 4 "skills": [ 5 { 6 "name": "JavaScript", 7 "level":"beginner" 8 }, 9 { 10 "name": "React", 11 ...
Discussions

jsonschema - JSON Schema definition for array of objects - Stack Overflow
I've seen this other question but it's not quite the same, and I feel like my issue is simpler, but just isn't working. My data would look like this: [ { "loc": "a value 1", "toll" : null, "m... More on stackoverflow.com
🌐 stackoverflow.com
jsonschema - JSON schema connecting arrays with properties - Stack Overflow
I've been asked to create JSON Schema with filetype called "zfs" containing array property pools, where each item of such array must have properties: name (string), volumes (array of strings), size... More on stackoverflow.com
🌐 stackoverflow.com
List of objects with required values
How do you define required values in a list? I have a list of objects with a property which is an enum with 10 options. But the list must contain at least 4 items with specific field values. For ex... More on github.com
🌐 github.com
1
1
June 30, 2022
Contains not working as expected with array of objects
JSON Schema is constraints based, and so anything you don't prohibit is allowed and considered valid. You haven't constrained additional properties using the additionalProperties keyword, so any key in the elements array objects are considered valid. More on github.com
🌐 github.com
4
1
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
Just as unevaluatedProperties affects only properties in an object, unevaluatedItems affects only items in an array. Watch out! The word "unevaluated" does not mean "not evaluated by items, prefixItems, or contains." "Unevaluated" means "not successfully evaluated", or "does not evaluate to true". Like with ...
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › object
JSON Schema - object
However, one can provide a list of required properties using the required keyword. 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. In the following example schema defining a user record, we require that each user has a name and e-mail address, but we don't mind if they don't provide their address or telephone number: ... { "type": "object", "properties": { "name": { "type": "string" }, "email": { "type": "string" }, "address": { "type": "string" }, "telephone": { "type": "string" } }, "required": ["name", "email"]}
Find elsewhere
🌐
Cswr
cswr.github.io › JsonSchema › spec › arrays
Arrays - JSON Schema
Here we show how to specify collections of JSON types using possibly nested JSON Schemas. Arrays are used to represent ordered sets of values, such as the following sequence of strings:
🌐
GitHub
github.com › orgs › json-schema-org › discussions › 145
Contains not working as expected with array of objects · json-schema-org · Discussion #145
{ "$schema": "http://json-schema.org/draft-07/schema", "properties": { "elements": { "type": "array", "items": { "type": "object" }, "contains": { "properties": { "somePropertyA": { "type": "string", "enum": [ "true" ] } } } } }, "required":["elements"], }
🌐
Cswr
cswr.github.io › JsonSchema › spec › objects
Objects - JSON Schema
The value of property is itself a key:value pair, while the value can be any JSON schema and it is used to specify how the value of the key:value pair should look. For example, the following schema specifies that objects should have at least two pairs, with keys first_name and last_name, and the values of those must be strings. { "type": "object", "required": ["first_name", "last_name"], "properties": { "first_name": {"type": "string"}, "last_name": {"type": "string"} } }
🌐
Ajv
ajv.js.org › json-schema.html
JSON Schema | Ajv JSON schema validator
If the data object contains a property that is a key in the keyword value, then to be valid the data object should also contain all properties from the corresponding array of properties in this keyword. ... The value of the keyword should be a map with keys equal to data object properties. Each value in the map should be a JSON Schema.
Top answer
1 of 4
28

I got it to work using this validator by nesting the part of the schema for the array elements inside a object with the name items. The schema now has two nested items fields, but that is because one is a keyword in JSONSchema and the other because your JSON actually has a field called items

JSONSchema:

{
   "type":"object",
   "properties":{
      "items":{
         "type":"array",
         "items":{
            "properties":{
               "item_id":{
                  "type":"number"
               },
               "quantity":{
                  "type":"number"
               },
               "price":{
                  "type":"number"
               },
               "title":{
                  "type":"string"
               },
               "description":{
                  "type":"string"
               }
            },
            "required":[
               "item_id",
               "quantity",
               "price",
               "title",
               "description"
            ],
            "additionalProperties":false
         }
      }
   }
}

JSON:

{
   "items":[
      {
         "item_id":1,
         "quantity":3,
         "price":30,
         "title":"item1 new name"
      },
      {
         "item_id":1,
         "quantity":16,
         "price":30,
         "title":"Test Two"
      }
   ]
}

Output with two errors about missing description fields:

[ {
  "level" : "error",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : "/properties/items/items"
  },
  "instance" : {
    "pointer" : "/items/0"
  },
  "domain" : "validation",
  "keyword" : "required",
  "message" : "missing required property(ies)",
  "required" : [ "description", "item_id", "price", "quantity", "title" ],
  "missing" : [ "description" ]
}, {
  "level" : "error",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : "/properties/items/items"
  },
  "instance" : {
    "pointer" : "/items/1"
  },
  "domain" : "validation",
  "keyword" : "required",
  "message" : "missing required property(ies)",
  "required" : [ "description", "item_id", "price", "quantity", "title" ],
  "missing" : [ "description" ]
} ]

Try pasting the above into here to see the same output generated.

2 of 4
10

I realize this is an old thread, but since this question is linked from jsonschema.net, I thought it might be worth chiming in...

The problem with your original example is that you're declaring "properties" for an "array" type, rather than declaring "items" for the array, and then declaring an "object" type (with "properties") that populates the array. Here's a revised version of the original schema snippet:

"items": {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "item_id": {"type" : "number"},
            "quantity": {"type": "number"},
            "price": {"type" : "decimal"},
            "title": {"type": "string"},
            "description": {"type": "string"}
        },
        "required": ["item_id","quantity","price","title","description"],
        "additionalProperties" : false
    }
}

I would recommend against using the term "items" for the name of the array, to avoid confusion, but there's nothing stopping you from doing that...

🌐
GeeksforGeeks
geeksforgeeks.org › json-schema
JSON Schema | GeeksforGeeks
June 22, 2020 - When arrays are defined, JSON schema uses the name-value pair "type":"array" Example: { "$id": "https://example.com/person.schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Voters information", "type": "object", "properties": { "firstName": { "type": "string", "description": "The person's first name."
🌐
JSON Schema
json-schema.org › understanding-json-schema › structuring
JSON Schema - Modular JSON Schema combination
The $ref keyword may be used to create recursive schemas that refer to themselves. For example, you might have a person schema that has an array of children, each of which are also person instances. ... { "type": "object", "properties": { "name": { "type": "string" }, "children": { "type": "array", "items": { "$ref": "#" } } }}
🌐
Json-schema
tour.json-schema.org › content › 01-Getting-Started › 05-Arrays
Arrays: Getting Started | A Tour of JSON Schema
Learn how to define arrays in JSON Schema using the type and items keywords, and convert properties to arrays of strings.
🌐
Google Groups
groups.google.com › g › json-schema › c › rgkxYocPSVg
JSON Schema: ordered properties
Strictly speaking objects in JSON are unordered, so such a property in JSON Schema wouldn't be of much use. Generally if you need an order, then you use an array, in the form of [{key: "x", value:"..."}]. But there can still be an informative property for serialization purposes, to say "serialize ...
🌐
Rjsf-team
rjsf-team.github.io › json schema › arrays
Arrays | react-jsonschema-form
import { RJSFSchema } from '@rjsf/utils'; import validator from '@rjsf/validator-ajv8'; const schema: RJSFSchema = { type: 'array', items: { type: 'object', properties: { name: { type: 'string', }, }, }, }; render(<Form schema={schema} validator={validator} />, document.getElementById('app'));
🌐
QA Touch
qatouch.com › home › validating json schema: all you need to know
Validating JSON Schema: All You Need To Know
June 24, 2025 - It requires an object with schemas or arrays of property names as values and property names as keys. The corresponding schema or array of property names must be present if the object’s key property is present.