GrepBoard/Manuals
605 manuals ·

Claude Code Error: --json-schema is not a valid JSON Schema

·Tested on Linux · Claude Code 2.1.330 · 2026-11·Test scope ↓·3 steps

Trace a Claude Code --json-schema failure to the type value. Compare the diagnostic with the earlier checks for malformed JSON and a top-level array.

output
Error: --json-schema is not a valid JSON Schema: data/type must be equal to one of the allowed values, data/type must be array, data/type must match a schema in anyOf

[1] Locate the failing keyword. The argument {"type":"bogus"} parses as JSON, but bogus is not a JSON Schema type name.

console
$ timeout 20 claude -p --setting-sources '' --json-schema '{"type":"bogus"}' 'List names'

All three parts of the diagnostic point to data/type. Edit the value of the top-level type keyword. Wrapping the whole schema in brackets in response to “must be array” would trigger an earlier check. This command exited with code 1 before processing the prompt.

[2] Look for the word Schema to distinguish the compilation error from two earlier failures. These commands keep the prompt and change only the flag value.

console
$ timeout 20 claude -p --setting-sources '' --json-schema '{broken' 'List names'
output
Error: --json-schema is not valid JSON: JSON Parse error: Expected '}'

The input ends before it forms a JSON object. In Bash, single-quote the entire argument to preserve the double quotes inside. The contents must still form a complete JSON value.

console
$ timeout 20 claude -p --setting-sources '' --json-schema '[]' 'List names'
output
Error: --json-schema must be a JSON object

An empty array parses as JSON. Claude Code requires an object at the top level of this flag. A diagnostic that names a schema keyword, like the one in step 1, means the value has already passed both checks. Official error reference

[3] Choose the types from the response you want. For a list of names under a names key, the outer response is an object, the list is an array, and each entry is a string. Pass the entire JSON object below as the value of --json-schema.

json
{"type":"object","properties":{"names":{"type":"array","items":{"type":"string"}}},"required":["names"]}

Listing names under required makes the key mandatory in the result object. The official guide pairs --output-format json with --json-schema and checks that the response contains structured_output before reading it. For a plain text answer wrapped in JSON, see reading the headless result field. Structured output guide

#claude-code#json-schema#cli