{"record":{"id":"7d61a63c32efebde","repo":"hasura/graphql-engine","slug":"parsing-metadata-as-json-w","errorCode":null,"errorMessage":"parsing metadata as json: %w","messagePattern":"parsing metadata as json: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":381,"sourceCode":"\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"displaying metadata failed: %w\", err))\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tif mode == cli.MetadataModeYAML {\n\t\tlocalMetadataBytes, err = metadatautil.YAMLToJSON(localMetadataBytes)\n\t\tif err != nil {\n\t\t\treturn 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 errors.E(op, fmt.Errorf(\"parsing metadata as json: %w\", err))\n\t}\n\n\tif o.EC.Config.Version == cli.V2 {\n\t\t_, err := cli.GetCommonMetadataOps(o.EC).\n\t\t\tReplaceMetadata(bytes.NewReader(localMetadataBytes))\n\t\tif err != nil {\n\t\t\treturn errors.E(op, err)\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tr, err := o.EC.APIClient.V1Metadata.V2ReplaceMetadata(hasura.V2ReplaceMetadataArgs{\n\t\tAllowInconsistentMetadata: !o.DisallowInconsistencies,\n\t\tMetadata:                  metadata,\n\t})\n\tif err != nil {\n\t\treturn errors.E(op, errorApplyingMetadata(err))","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L363-L399","documentation":"After any YAML-to-JSON conversion, `metadata apply` unmarshals the metadata bytes with json.Unmarshal into a generic `any`. This error means the (converted) bytes are not valid JSON — the local metadata file is corrupt at the JSON level, or the YAML conversion produced something unparseable.","triggerScenarios":"`metadata apply` where json.Unmarshal of the metadata file bytes fails: invalid JSON syntax (trailing commas, comments, single quotes), empty file, BOM prefix, or truncated file from a bad export or edit.","commonSituations":"Hand-edited metadata.json with comments or trailing commas (not valid JSON); file truncated by an interrupted write; file saved with UTF-8 BOM by an editor; empty file created accidentally.","solutions":["Run jq . metadata.json to get the exact parse error location","Remove comments/trailing commas, ensure standard JSON syntax","Re-export metadata from the server to restore a known-good file, then re-apply changes","Ensure the file is saved as UTF-8 without BOM and is non-empty"],"exampleFix":"# before\nhasura metadata apply  # parsing metadata as json: invalid character ',' ...\n# after\njq . metadata.json  # fix trailing comma, then\nhasura metadata apply","handlingStrategy":"validation","validationCode":"data, _ := os.ReadFile(ec.MetadataFile)\nif len(data) == 0 { return errors.New(\"metadata file empty\") }\nvar v any\nif err := json.Unmarshal(data, &v); err != nil {\n  return fmt.Errorf(\"metadata file invalid JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := apply(o, mode); err != nil {\n  if strings.Contains(err.Error(), \"parsing metadata as json\") {\n    // jq . metadata.json to find the exact syntax problem\n  }\n}","preventionTips":["Use jq to validate hand-edited JSON metadata","Save files as UTF-8 without BOM","Never put comments or trailing commas in JSON metadata"],"tags":["metadata","apply","json","parsing","cli"],"backgroundTag":"json-parse-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}