Claude Code Error: --json-schema is not a valid JSON Schema
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.
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.
$ 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.
$ timeout 20 claude -p --setting-sources '' --json-schema '{broken' 'List names'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.
$ timeout 20 claude -p --setting-sources '' --json-schema '[]' 'List names'Error: --json-schema must be a JSON objectAn 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.
{"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