{"record":{"id":"1a576fcf04000732","repo":"gotify/server","slug":"invalid-json-for-s-w","errorCode":null,"errorMessage":"invalid JSON for %s: %w","messagePattern":"invalid JSON for (.+?): %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/parse.go","lineNumber":103,"sourceCode":"\trecord, err := reader.Read()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid CSV for %s (%q): %w\", env, raw, err)\n\t}\n\t*target = record\n\treturn nil\n}\n\nfunc parseMap(target *map[string]string, env string) error {\n\traw, ok, err := lookupEnv(env)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !ok || raw == \"\" {\n\t\treturn nil\n\t}\n\tout := map[string]string{}\n\tif err := json.Unmarshal([]byte(raw), &out); err != nil {\n\t\treturn fmt.Errorf(\"invalid JSON for %s: %w\", env, err)\n\t}\n\t*target = out\n\treturn nil\n}\n\nfunc parseLogLevel(target *LogLevel, env string) error {\n\traw, ok, err := lookupEnv(env)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif !ok {\n\t\treturn nil\n\t}\n\treturn target.Decode(raw)\n}\n","sourceCodeStart":85,"sourceCodeEnd":119,"githubUrl":"https://github.com/gotify/server/blob/14bfc256276775c425f988d621dccfe705de18ac/config/parse.go#L85-L119","documentation":"parseMap unmarshals a JSON-encoded environment/config value into a map[string]string. When json.Unmarshal fails because the raw string is not a valid JSON object with string values, it wraps the underlying error with the environment variable name for context.","triggerScenarios":"Get is called for a config key whose raw env value is non-empty but is not a valid JSON object, e.g. a value missing quotes around keys, using single quotes, trailing commas, or containing non-string values.","commonSituations":"Developers set env vars like FOO_MAP={\"a\":1} (integer value) or FOO_MAP={'a':'b'} (single quotes from shell habits) instead of strictly valid JSON with string values: {\"a\":\"b\"}.","solutions":["Fix the env var value to be a valid JSON object with only string values, e.g. {\"key\":\"value\"}","Validate the JSON locally (e.g. echo '<value>' | jq .) before deploying","If the value is meant to be a plain string, use the appropriate non-map accessor instead of the map parser"],"exampleFix":"// before\nMY_MAP={'a':'b'}\n// after\nMY_MAP={\"a\":\"b\"}","handlingStrategy":"validation","validationCode":"raw := os.Getenv(\"MY_MAP\")\nif raw != \"\" {\n    var probe map[string]string\n    if err := json.Unmarshal([]byte(raw), &probe); err != nil {\n        return fmt.Errorf(\"MY_MAP is not valid JSON: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"m, err := cfg.Get(\"MY_MAP\")\nif err != nil {\n    var je *json.SyntaxError\n    if errors.As(err, &je) {\n        log.Fatalf(\"fix MY_MAP JSON near offset %d\", je.Offset)\n    }\n    return err\n}","preventionTips":["Always use double-quoted, valid JSON for map-type env vars","Validate JSON values in CI before deployment","Use a JSON linter or jq to check values","Prefer dedicated scalar accessors for non-map values"],"tags":["config","json","environment-variables"],"backgroundTag":"invalid-json-parsing","analyzedSha":"14bfc256276775c425f988d621dccfe705de18ac","analyzedAt":"2026-09-05T12:52:36.781Z","contentChangedAt":"2026-09-05T12:52:36.781Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}