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 OverflowJSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
In Python, "array" is analogous to the list or tuple type, depending on usage. However, the json module in the Python standard library will always use Python lists to represent JSON arrays. ... List validation: a sequence of arbitrary length where each item matches the same schema.
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
Json schema array define ordering
When defining an array in a json schema, I would like to be able to define the items of the array to be in ascending/descending order. More on github.com
JSON Schema: How to require a value to be one of another properties array values
As far as I know, JSON doesn’t support dynamic values or constraints. I think you would need a validator library to help More on reddit.com
Opis JSON Schema: Is it possible to generate a schema from a PHP array or object?
Looking at the docs here , your example lacks "properties" => (object) [ and "myString" => (object) [. Note that casting an array to object isn't a recursive operation, so you need to manually cast everything withing the schema that need to be an object. Alternatives: Start with actual object: $schema = new stdClass; The validator accepts JSON encoded stings, so you can json_encode the array or use the Helper::toJSON() method. PS: I tried to achieve this and I keep getting several Fatal Errors in PHP It's very important to try to understand those error messages, as they likely point to the fix. Or at least include then in your post, so we know about them. When reading your post, I was unsure if the example provided was the one having errors. More on reddit.com
Videos
12:18
Why does JSON Schema validate so many things? Add More Constraints!
35:46
An Introduction to JSON Schema: A Practical Look - YouTube
12:49
Part 15 - Rest Assured - JSON Schema Validation - YouTube
15:20
What is a JSON Schema? Intro to JSON - YouTube
05:27
How to Use Itential's JSON Schema Transformation Array Map - YouTube
05:27
How to Use Itential's JSON Schema Transformation Array Filter - ...
Cswr
cswr.github.io › JsonSchema › spec › arrays
Arrays - JSON Schema
In this case, we are asking that the first element must be a string, the second one an integer and the third one a boolean. For example, this array validates against the schema ... Note that the default behaviour of JSON Schema allows us to have fewer items, as long as the corresponding (sub)schemas are satisfied.
JSON Schema
json-schema.org › learn › miscellaneous-examples
JSON Schema - Miscellaneous Examples
This example introduces the enum validation keyword which is used with an array of values that includes an integer (42), a boolean (true), a string ("hello"), null, and an array ([1, 2, 3]). This demonstrates how enum can be used to specify a set of allowed values of different types. ... { "$id": "https://example.com/enumerated-values.schema.json", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Enumerated Values", "type": "object", "properties": { "data": { "enum": [42, true, "hello", null, [1, 2, 3]] } }}
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.
Json-schema
tour.json-schema.org › content › 01-Getting-Started › 06-Array-of-Objects
Array of Objects: Getting Started | A Tour of JSON Schema
Learn how to define an array of objects with properties name and level, and how to set the items keyword in JSON schema.
Firebase
firebase.google.com › documentation › firebase ai logic › generate structured output (like json and enums) using the gemini api
Generate structured output (like JSON and enums) using the Gemini API | Firebase AI Logic
5 days ago - To ensure that the model's generated output always adheres to a specific schema, you can define a response schema which works like a blueprint for model responses. You can then directly extract data from the model's output with less post-processing. ... Ensure that a model's response produces valid JSON and conforms to your provided schema.
MuleSoft
help.mulesoft.com › s › question › 0D52T00004mXUrdSAG › how-do-you-define-an-array-containing-arrays-in-a-json-schema
How do you define an array containing arrays in a JSON ...
March 6, 2017 - Loading · ×Sorry to interrupt · Refresh
Opis
opis.io › json-schema › 2.x › array.html
Array type | Opis JSON Schema
An array is valid against this keyword if items are valid against the corresponding schemas provided by the keyword value. The value of this keyword must be an array of valid json schemas, and each item must be valid against the schema defined at the same position (index).
IBM
ibm.com › docs › en › cics-ts › 6.x
Variable arrays of elements in DFHJS2LS
JSON can contain arrays of varying numbers of elements. In general JSON Schemas that contain varying numbers of elements do not map efficiently into a single high-level language data structure. CICS uses container-based mappings or inline mappings to handle varying numbers of elements in JSON data.
Json-schema
tour.json-schema.org › content › 04-Arrays › 01-Specifying-Length-of-an-Array
Specifying Length of an Array: Arrays | A Tour of JSON Schema
Consider the employee JSON Document, now has a new field: an array of phone numbers. 1{ 2 "name": "John Doe", 3 "age": 25, 4 "phones": ["123-456-7890", "987-654-3210"] 5} In JSON Schema, you can specify the minimum and maximum number of items in an array using the minItems and maxItems keywords.
Gsu
tinman.cs.gsu.edu › ~raj › 8711 › sp21 › json › JSONSchema.html
JSON and JSON Schema
JSON Schema is a specification that allows us to "describe" the structure of the JSON representations.
W3Schools
w3schools.com › js › js_json_datatypes.asp
JSON Data Types
Values in JSON can be arrays.
GitHub
github.com › json-schema-org › json-schema-spec › issues › 1197
Json schema array define ordering · Issue #1197 · json-schema-org/json-schema-spec
February 14, 2022 - { "$schema": "http://json-schema.org/draft-07/schema", "type": "array", "additionalItems": false, >>>>> "sort": "ascending", "items": { "type": "string" }
Author Willem-J-an
Wikipedia
en.wikipedia.org › wiki › JSON
JSON - Wikipedia
March 6, 2005 - String: a sequence of zero or more Unicode characters. Strings are delimited with double quotation marks and support a backslash escaping syntax. ... Array: an ordered list of zero or more elements, each of which may be of any type.
Google AI
ai.google.dev › gemini api › structured outputs
Structured outputs | Gemini API | Google AI for Developers
January 12, 2026 - required: An array of strings, listing which properties are mandatory. additionalProperties: Controls whether properties not listed in properties are allowed. Can be a boolean or a schema. ... * Note that Gemini 2.0 requires an explicit propertyOrdering list within the JSON input to define the preferred structure.