JSON Schema arrays and strings, and what local grammars support
Answer: For list validation, set items to a single schema used to validate all items. For tuple validation, use prefixItems, where each item is a schema corresponding to an index in the array. Set array length with minItems/maxItems and uniqueness with uniqueItems: true. For strings, minLength/maxLength set length and pattern applies a regular expression.
The pattern gotcha
A pattern matches anywhere within the string, so "p" matches "apple". Surround the expression with ^...$ unless there is a good reason not to.
llama.cpp JSON Schema limits
llama.cpp converts only a subset of JSON Schema to GBNF. The documentation lists these limits:
prefixItemsis broken, butitemsworks.minimumandmaximumare only supported for"type": "integer".- Patterns must start with
^and end with$; there are no string formats forurioremail. uniqueItemsandcontainsare unlikely to be implemented.- Unsupported features are skipped silently.
See also
- ao-structured-json-schema-objects
- ao-structured-ollama-and-llamacpp-grammars
- ao-structured-across-providers
- ao-structured-gemini-json-schema
Claims
- id: C1 claim: uniqueItems requires unique elements. source: S1 evidence: "Simply set the
uniqueItemskeyword totrue."
- id: C2 claim: pattern restricts strings by regex. source: S2 evidence: "The
patternkeyword is used to restrict a string to a particular"
- id: C3 claim: Unsupported features are skipped silently. source: S3 evidence: "Unsupported features are skipped silently."
Sources
- [S1] Understanding JSON Schema: array. json-schema-org/website (GitHub). https://github.com/json-schema-org/website/blob/main/pages/understanding-json-schema/reference/array.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S2] Understanding JSON Schema: string. json-schema-org/website (GitHub). https://github.com/json-schema-org/website/blob/main/pages/understanding-json-schema/reference/string.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S3] GBNF guide (llama.cpp grammars README). ggml-org/llama.cpp (GitHub). https://github.com/ggml-org/llama.cpp/blob/master/grammars/README.md . License: MIT. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: json-schema-org/website (GitHub), Understanding JSON Schema: array, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; json-schema-org/website (GitHub), Understanding JSON Schema: string, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; ggml-org/llama.cpp (GitHub), GBNF guide (llama.cpp grammars README), MIT (https://raw.githubusercontent.com/ggml-org/llama.cpp/master/LICENSE). Copyright (c) 2023-2026 The ggml authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: json-schema-org/website (GitHub), Understanding JSON Schema: array, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; json-schema-org/website (GitHub), Understanding JSON Schema: string, BSD-3-Clause (https://raw.githubusercontent.com/json-schema-org/website/main/LICENSE). Copyright (c) 2022 JSON Schema Specification Authors; ggml-org/llama.cpp (GitHub), GBNF guide (llama.cpp grammars README), MIT (https://raw.githubusercontent.com/ggml-org/llama.cpp/master/LICENSE). Copyright (c) 2023-2026 The ggml authors.
Cite this
iinventedlight. 2026. "JSON Schema arrays and strings, and what local grammars support." iinventedlight Library, iil:note:t2fy47gj, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-structured-json-schema-arrays-and-strings/. License: CC-BY-4.0.
@misc{iil_note_t2fy47gj,
author = {{iinventedlight}},
title = {{JSON Schema arrays and strings, and what local grammars support}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-structured-json-schema-arrays-and-strings/},
note = {Permanent ID iil:note:t2fy47gj. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-structured-json-schema-arrays-and-strings.md.