micro-editor/micro · error

Error reading settings.json: %s

Error message

Error reading settings.json: %s

What it means

Returned by config.ReadSettings when the contents of settings.json cannot be unmarshalled by the JSON5 parser. JSON5 permits comments, trailing commas and unquoted keys, but the file must still be structurally valid; the parser's message (offset/position included) is wrapped verbatim. settingsParseError is set, protecting the file from being overwritten by in-session changes.

Source

Thrown at internal/config/settings.go:254

	}
	return err
}

func ReadSettings() error {
	parsedSettings = make(map[string]any)
	filename := filepath.Join(ConfigDir, "settings.json")
	if _, e := os.Stat(filename); e == nil {
		input, err := os.ReadFile(filename)
		if err != nil {
			settingsParseError = true
			return errors.New("Error reading settings.json file: " + err.Error())
		}
		if !strings.HasPrefix(string(input), "null") {
			// Unmarshal the input into the parsed map
			err = json5.Unmarshal(input, &parsedSettings)
			if err != nil {
				settingsParseError = true
				return errors.New("Error reading settings.json: " + err.Error())
			}
			err = validateParsedSettings()
			if err != nil {
				return err
			}
		}
	}
	return nil
}

func ParsedSettings() map[string]any {
	s := make(map[string]any)
	for k, v := range parsedSettings {
		if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
			continue
		}
		s[k] = v
	}

View on GitHub (pinned to 1c8b82b32e)

Solutions

  1. Open the file and jump to the offset the parser reports; fix or remove the malformed fragment.
  2. Validate quickly: run `micro ~/.config/micro/settings.json` in a fresh instance — JSON5 comments are fine, so you can keep notes.
  3. If hopeless, back up and start over: mv settings.json settings.json.bak and let micro regenerate defaults, then re-add your options incrementally.
  4. After fixing, confirm no more error on startup and that settings changes persist again (settingsParseError clears on next clean load).

Example fix

// before (~/.config/micro/settings.json):
{ "tabsize": 4, "autosave": true,   // trailing comma then EOF -> parse error

// after:
{
  "tabsize": 4,
  "autosave": true
}
Defensive patterns

Strategy: validation

Validate before calling

import "github.com/yosida95/uritemplate/v3" // no — use a JSON5 validator:
import "github.com/titanous/json5"

func validJSON5Settings(data []byte) bool {
    var v map[string]any
    return json5.Unmarshal(data, &v) == nil
}

// before saving a generated settings.json:
if !validJSON5Settings(out) { /* regenerate from defaults */ }

Try / catch

if err := config.ReadSettings(); err != nil {
    if strings.HasPrefix(err.Error(), "Error reading settings.json:") {
        // parse failure: back up file, restore last good copy or defaults, re-run ReadSettings
    }
}

Prevention

When it happens

Trigger: An unbalanced brace/bracket, a stray comma between pairs in strict positions JSON5 disallows, an unterminated string, or a literal like {'a': undef} — anything json5.Unmarshal rejects at internal/config/settings.go:254. Note a file starting with the literal text 'null' is skipped entirely.

Common situations: Hand-editing settings.json and losing a brace, pasting config snippets from websites that include smart quotes or HTML entities, or a crashed concurrent write truncating the file.

Related errors


AI-assisted analysis of micro-editor/micro@1c8b82b32e (2026-08-15). Data as JSON: /api/errors/48f36ca91c8418c1. Report an issue: GitHub.