{"record":{"id":"156beed0db811a6f","repo":"Tencent/WeKnora","slug":"json-conversion-failed-w","errorCode":null,"errorMessage":"json conversion failed: %w","messagePattern":"json conversion failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/builtin_converter.go","lineNumber":70,"sourceCode":"\tif ft == \"\" {\n\t\tft = strings.TrimPrefix(strings.ToLower(filepath.Ext(req.FileName)), \".\")\n\t}\n\n\tswitch {\n\tcase ft == \"md\" || ft == \"markdown\":\n\t\treturn &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil\n\tcase ft == \"txt\" || ft == \"text\":\n\t\treturn &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil\n\tcase ft == \"csv\":\n\t\tmd, err := csvToMarkdown(req.FileContent)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"csv conversion failed: %w\", err)\n\t\t}\n\t\treturn &types.ReadResult{MarkdownContent: md}, nil\n\tcase ft == \"json\":\n\t\tmd, err := jsonToMarkdown(req.FileContent)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"json conversion failed: %w\", err)\n\t\t}\n\t\treturn &types.ReadResult{MarkdownContent: md}, nil\n\tcase imageFormats[ft]:\n\t\treturn imageToResult(req.FileName, req.FileContent), nil\n\tcase audioFormats[ft]:\n\t\treturn audioToResult(req.FileName, req.FileContent), nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported simple format: %s\", ft)\n\t}\n}\n\n// imageToResult wraps a standalone image as a markdown image reference with\n// the raw bytes in ImageRefs, matching Python ImageParser behaviour.\nfunc imageToResult(fileName string, data []byte) *types.ReadResult {\n\tif fileName == \"\" {\n\t\tfileName = \"image.png\"\n\t}\n\trefPath := \"images/\" + fileName","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/builtin_converter.go#L52-L88","documentation":"The built-in document converter converts JSON files to Markdown via jsonToMarkdown. This error wraps failures converting the uploaded JSON — almost always invalid JSON syntax (trailing commas, comments, single quotes, truncated file, or non-JSON content with a .json extension).","triggerScenarios":"Calling Read with file type \"json\" where json.Unmarshal inside jsonToMarkdown fails: truncated download, BOM prefix, NaN/Infinity literals, duplicate handling errors, or content that isn't actually JSON.","commonSituations":"Files renamed to .json but containing JSON5/JSONC (comments) or log lines; truncated uploads; UTF-16 encoded exports; single-quoted JS object literals saved as .json.","solutions":["Validate the file with a strict JSON parser (jq, python -m json.tool) and fix the reported syntax error.","Re-upload the file; a truncated/corrupt download is a common cause.","Convert JSON5/JSONC (comments, trailing commas) to strict JSON before upload.","Check the file encoding is UTF-8 without BOM; re-save if needed."],"exampleFix":"// before\n{ name: 'Bob', age: 3, } // JSON5, invalid strict JSON\n// after\n{\"name\": \"Bob\", \"age\": 3}","handlingStrategy":"validation","validationCode":"if !json.Valid(bytes.TrimPrefix(req.FileContent, []byte(\"\\xef\\xbb\\xbf\"))) {\n    return fmt.Errorf(\"file is not valid JSON\")\n}","typeGuard":"func isStrictJSON(data []byte) bool {\n    return json.Valid(bytes.TrimPrefix(data, []byte(\"\\xef\\xbb\\xbf\")))\n}","tryCatchPattern":"res, err := reader.Read(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"json conversion failed\") {\n    var syn *json.SyntaxError\n    if errors.As(err, &syn) { log.Printf(\"JSON syntax error at offset %d\", syn.Offset) }\n}","preventionTips":["Validate JSON with a strict parser (jq / python -m json.tool) before upload.","Ban JSON5/JSONC features (comments, trailing commas) in .json files.","Ensure uploads complete — truncated files are a common cause.","Save as UTF-8 without BOM; avoid UTF-16 exports."],"tags":["json","docparser","conversion","format"],"backgroundTag":"invalid-json","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}