{"record":{"id":"97eb197a7d6ffa01","repo":"micro-editor/micro","slug":"error-reading-bindings-json-s","errorCode":null,"errorMessage":"Error reading bindings.json: %s","messagePattern":"Error reading bindings\\.json: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/action/bindings.go","lineNumber":289,"sourceCode":"}\n\n// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json\n// Returns true if the keybinding already existed or is binded successfully and a possible error\nfunc TryBindKey(k, v string, overwrite bool, writeToFile bool) (bool, error) {\n\tvar e error\n\tvar parsed map[string]any\n\n\tfilename := filepath.Join(config.ConfigDir, \"bindings.json\")\n\tcreateBindingsIfNotExist(filename)\n\tif _, e = os.Stat(filename); e == nil {\n\t\tinput, err := os.ReadFile(filename)\n\t\tif err != nil {\n\t\t\treturn false, errors.New(\"Error reading bindings.json file: \" + err.Error())\n\t\t}\n\n\t\terr = json5.Unmarshal(input, &parsed)\n\t\tif err != nil {\n\t\t\treturn false, errors.New(\"Error reading bindings.json: \" + err.Error())\n\t\t}\n\n\t\tkey, err := findEvent(k)\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}\n\n\t\tfound := false\n\t\tvar ev string\n\t\tfor ev = range parsed {\n\t\t\tif e, err := findEvent(ev); err == nil {\n\t\t\t\tif eventsEqual(e, key) {\n\t\t\t\t\tfound = true\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/micro-editor/micro/blob/1c8b82b32e408a5faf340039ed92d5266bea3293/internal/action/bindings.go#L271-L307","documentation":"Returned by TryBindKey (internal/action/bindings.go:289) when the contents of bindings.json cannot be parsed as JSON5. Micro uses the json5 library, so comments, unquoted keys and trailing commas are legal; the error fires only on genuinely broken syntax such as unbalanced braces, unterminated strings, or a stray single quote inside a double-quoted value. The json5 error text (with line/column) is appended.","triggerScenarios":"Running > bind or > default after hand-editing bindings.json and leaving a syntax error: missing comma creating an invalid token, unescaped quote in an action name, a dangling '}' — json5.Unmarshal fails and the error wraps the parser message.","commonSituations":"Editing bindings.json while micro is open, then the editor auto-writing the file on the next bind command; merging config snippets by hand; smart-quote substitution when pasting through a chat app.","solutions":["Open the json5 error text: it names the position — jump to that line in bindings.json and fix the brace/quote/comma","Validate before retrying: python3 -c \"import json,sys; json.load(sys.stdin)\" < bindings.json (after stripping // lines) or any JSON5 linter","Fall back to the well-known-good default: mv bindings.json bindings.json.bak, restart micro (fresh '{}' created), re-add bindings incrementally","Avoid unescaped double quotes inside values or switch those strings to single quotes, which JSON5 accepts"],"exampleFix":"// before: ~/.config/micro/bindings.json (missing comma)\n\"CtrlS\": \"Save\"\n\"CtrlQ\": \"QuitAll\"\n\n// after\n\"CtrlS\": \"Save\",\n\"CtrlQ\": \"QuitAll\",","handlingStrategy":"validation","validationCode":"// Pre-validate JSON5 syntax before invoking bind (uses the same lib micro uses)\nimport \"github.com/micro-editor/json5\"\n\nfunc bindingsParse(path string) error {\n    data, err := os.ReadFile(path)\n    if err != nil { return err }\n    var m map[string]any\n    return json5.Unmarshal(data, &m)\n}","typeGuard":null,"tryCatchPattern":"if _, err := action.TryBindKey(k, v, true, true); err != nil {\n    if strings.HasPrefix(err.Error(), \"Error reading bindings.json:\") {\n        // parse error: parse the appended position, offer to restore last good copy\n        return restoreLastGoodBindings(err)\n    }\n    return err\n}","preventionTips":["Keep a bindings.json.bak copy; micro will not auto-restore a broken file","Remember JSON5 is allowed: use // comments and single quotes rather than fighting JSON quoting","After every manual edit, run one harmless >bind to force a parse before restarting"],"tags":["config","json","json5","parsing","keybinding"],"backgroundTag":null,"analyzedSha":"1c8b82b32e408a5faf340039ed92d5266bea3293","analyzedAt":"2026-08-15T20:01:45.134Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}