{"record":{"id":"39112584ed505df4","repo":"d2lang/d2","slug":"decode-diagram-hash-json-got-closing-token-v-wa","errorCode":null,"errorMessage":"decode diagram hash JSON: got closing token %v, want }","messagePattern":"decode diagram hash JSON: got closing token (.+?), want \\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2target/d2target.go","lineNumber":304,"sourceCode":"\n\t\t\t\tstable, err := stableHashURL(raw)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tvalueEnd := int(dec.InputOffset())\n\t\t\t\tif valueEnd < valueStart || valueEnd > len(b) {\n\t\t\t\t\treturn fmt.Errorf(\"decode icon URL for stable diagram hash: invalid offsets %d:%d\", valueStart, valueEnd)\n\t\t\t\t}\n\t\t\t\tout.Write(b[lastWrite:valueStart])\n\t\t\t\tout.Write(stable)\n\t\t\t\tlastWrite = valueEnd\n\t\t\t}\n\t\t\tcloseToken, err := dec.Token()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif closeToken != json.Delim('}') {\n\t\t\t\treturn fmt.Errorf(\"decode diagram hash JSON: got closing token %v, want }\", closeToken)\n\t\t\t}\n\t\tcase '[':\n\t\t\tfor dec.More() {\n\t\t\t\tif err := walkValue(); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\t\tcloseToken, err := dec.Token()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif closeToken != json.Delim(']') {\n\t\t\t\treturn fmt.Errorf(\"decode diagram hash JSON: got closing token %v, want ]\", closeToken)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"decode diagram hash JSON: unexpected delimiter %q\", delim)\n\t\t}\n\t\treturn nil","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2target/d2target.go#L286-L322","documentation":"While walking nested JSON arrays during stable hashing, each object must be closed with '}'. If the decoder returns a different token where the object close is expected, this error reports the offending token. It means the JSON structure is not a well-formed object at that position.","triggerScenarios":"Stable-hashing JSON with mismatched brackets — e.g. an object terminated by ']' instead of '}' — usually from corrupted, truncated, or hand-edited diagram JSON.","commonSituations":"Manual string surgery on diagram JSON; partial reads from cache files; regex-based JSON rewriting that broke bracket pairing.","solutions":["Validate the JSON with json.Valid before hashing","Re-serialize the diagram from the compiled d2target.Diagram rather than editing serialized JSON","Fix the generator/editor that produced mismatched brackets"],"exampleFix":"// before\nb = []byte(`{\"icon\": [\"url\"]`) // missing }\n// after\nb = []byte(`{\"icon\": [\"url\"]}`)","handlingStrategy":"validation","validationCode":"if !json.Valid(b) {\n\treturn errors.New(\"diagram JSON is malformed\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never patch serialized JSON with string/regex edits","Validate JSON before hashing","Regenerate from the source diagram instead of editing output"],"tags":["json","hashing","structure"],"backgroundTag":"malformed-json-input","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}