{"record":{"id":"4c3c164bdefb21f4","repo":"hasura/graphql-engine","slug":"parsing-metadata-as-json-w-4c3c16","errorCode":null,"errorMessage":"parsing metadata as json: %w","messagePattern":"parsing metadata as json: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/pkg/metadata/mode_handlers.go","lineNumber":246,"sourceCode":"\tif err != nil {\n\t\treturn nil, errors.E(op, fmt.Errorf(\"reading metadata file: %w\", err))\n\t}\n\n\tif mode == cli.MetadataModeYAML {\n\t\tlocalMetadataBytes, err = metadatautil.YAMLToJSON(localMetadataBytes)\n\t\tif err != nil {\n\t\t\treturn nil, errors.E(op, fmt.Errorf(\"parsing yaml metadata to json: %w\", err))\n\t\t}\n\t}\n\n\tvar metadata any\n\n\terr = json.Unmarshal(localMetadataBytes, &metadata)\n\tif err != nil {\n\t\treturn nil, errors.E(\n\t\t\top,\n\t\t\terrors.KindBadInput,\n\t\t\tfmt.Errorf(\"parsing metadata as json: %w\", err),\n\t\t)\n\t}\n\n\tif p.ec.Config.Version == cli.V2 {\n\t\tr, err := cli.GetCommonMetadataOps(p.ec).\n\t\t\tReplaceMetadata(bytes.NewReader(localMetadataBytes))\n\t\tif err != nil {\n\t\t\treturn nil, errors.E(op, err)\n\t\t}\n\n\t\treturn r, nil\n\t}\n\n\tr, err := p.ec.APIClient.V1Metadata.V2ReplaceMetadata(hasura.V2ReplaceMetadataArgs{\n\t\tAllowInconsistentMetadata: true,\n\t\tMetadata:                  metadata,\n\t})\n\tif err != nil {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/pkg/metadata/mode_handlers.go#L228-L264","documentation":"After optionally converting YAML, the CLI unmarshals the metadata bytes as JSON into an any. This error (marked errors.KindBadInput) means the metadata content is not valid JSON — malformed syntax, a BOM, trailing garbage, or non-text bytes. For YAML mode it can also mean YAMLToJSON produced content that still is not valid JSON, though usually the YAML step catches that first.","triggerScenarios":"Calling Apply with a metadata file whose bytes fail json.Unmarshal: trailing commas, single quotes, comments (invalid in JSON), a UTF-8 BOM, or an empty/corrupted file. This is classified KindBadInput, i.e. user-provided input is at fault.","commonSituations":"Hand-editing metadata.json with JSON-incompatible syntax (comments, trailing commas); editor saving with BOM; truncated file from an interrupted export; applying a YAML file while running in JSON mode.","solutions":["Validate with `jq . metadata/metadata.json` (or `python -m json.tool`) to locate the exact syntax error","Remove comments, trailing commas, and ensure the file is a single valid JSON value","Re-export metadata to get a known-good file: `hasura metadata export`","Confirm the metadata mode matches the file format (YAML file with YAML mode, JSON with JSON)"],"exampleFix":"// before (metadata.json)\n{\n  \"version\": 3, // v3  <- comments invalid in JSON\n}\n// after\n{\n  \"version\": 3\n}","handlingStrategy":"validation","validationCode":"import \"encoding/json\"\nvar v any\nif err := json.Unmarshal(raw, &v); err != nil {\n    return fmt.Errorf(\"metadata file is not valid JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate JSON in CI with jq before apply","Keep the metadata mode flag consistent with the file format","Avoid hand-editing metadata.json; edit, export, review"],"tags":["json","parsing","metadata","bad-input","hasura-cli"],"backgroundTag":"json-parse-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}