{"record":{"id":"e446f28bde74463b","repo":"d2lang/d2","slug":"decode-diagram-hash-json-got-closing-token-v-wa-e446f2","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":317,"sourceCode":"\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\n\t}\n\n\tif err := walkValue(); err != nil {\n\t\treturn nil, err\n\t}\n\tout.Write(b[lastWrite:])\n\treturn out.Bytes(), nil\n}\n\nfunc hashJSONValueStart(b []byte, keyEnd int) (int, error) {\n\ti := keyEnd\n\tfor i < len(b) && (b[i] == ' ' || b[i] == '\\t' || b[i] == '\\r' || b[i] == '\\n') {\n\t\ti++","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2target/d2target.go#L299-L335","documentation":"Symmetric to the object-close check: while walking nested JSON, every array must be closed with ']'. A different closing token triggers this error, indicating malformed structure in the diagram JSON being stable-hashed.","triggerScenarios":"Stable-hashing JSON where an array is closed with '}' or another token instead of ']' — corrupt or hand-edited diagram JSON.","commonSituations":"Regex/text-based edits to diagram JSON; truncated cached JSON; generated JSON from a buggy custom serializer.","solutions":["Validate the JSON with json.Valid before hashing","Re-serialize from the compiled diagram instead of editing serialized output","Fix the upstream producer emitting mismatched array closers"],"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","Fix upstream JSON producers emitting mismatched brackets"],"tags":["json","hashing","structure"],"backgroundTag":"malformed-json-input","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}