micro-editor/micro · error
Error reading bindings.json: %s
Error message
Error reading bindings.json: %s
What it means
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.
Source
Thrown at internal/action/bindings.go:289
}
// TryBindKey tries to bind a key by writing to config.ConfigDir/bindings.json
// Returns true if the keybinding already existed or is binded successfully and a possible error
func TryBindKey(k, v string, overwrite bool, writeToFile bool) (bool, error) {
var e error
var parsed map[string]any
filename := filepath.Join(config.ConfigDir, "bindings.json")
createBindingsIfNotExist(filename)
if _, e = os.Stat(filename); e == nil {
input, err := os.ReadFile(filename)
if err != nil {
return false, errors.New("Error reading bindings.json file: " + err.Error())
}
err = json5.Unmarshal(input, &parsed)
if err != nil {
return false, errors.New("Error reading bindings.json: " + err.Error())
}
key, err := findEvent(k)
if err != nil {
return false, err
}
found := false
var ev string
for ev = range parsed {
if e, err := findEvent(ev); err == nil {
if eventsEqual(e, key) {
found = true
break
}
}
}
View on GitHub (pinned to 1c8b82b32e)
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
Example fix
// before: ~/.config/micro/bindings.json (missing comma) "CtrlS": "Save" "CtrlQ": "QuitAll" // after "CtrlS": "Save", "CtrlQ": "QuitAll",
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate JSON5 syntax before invoking bind (uses the same lib micro uses)
import "github.com/micro-editor/json5"
func bindingsParse(path string) error {
data, err := os.ReadFile(path)
if err != nil { return err }
var m map[string]any
return json5.Unmarshal(data, &m)
} Try / catch
if _, err := action.TryBindKey(k, v, true, true); err != nil {
if strings.HasPrefix(err.Error(), "Error reading bindings.json:") {
// parse error: parse the appended position, offer to restore last good copy
return restoreLastGoodBindings(err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid event %s
- %s is not a bindable event
- Error reading settings.json: %s
- Error reading bindings.json file: %s
- Color-link statement is not valid: %s
AI-assisted analysis of micro-editor/micro@1c8b82b32e (2026-08-15).
Data as JSON: /api/errors/97eb197a7d6ffa01.
Report an issue: GitHub.