{"record":{"id":"e2feb9f71cb55ee5","repo":"Tencent/WeKnora","slug":"empty-json-content","errorCode":null,"errorMessage":"empty JSON content","messagePattern":"empty JSON content","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/infrastructure/docparser/json_converter.go","lineNumber":32,"sourceCode":"const defaultJSONChunkSize = 1536\n\n// minJSONChunkSize is the minimum chunk size. A new chunk is only started\n// when the current chunk has reached at least this size.\nvar minJSONChunkSize = defaultJSONChunkSize - 200\n\n// jsonToMarkdown converts raw JSON bytes into markdown text\n//\n// Key properties:\n//   - Every output chunk is a **valid JSON object** (not a fragment).\n//   - Nested paths from root to leaf are **fully preserved** in each chunk.\n//   - Arrays are converted to index-keyed dicts so the algorithm is uniform.\n//   - Small objects that fit within maxChunkSize are kept intact (not split).\n//   - The output is a series of fenced ```json code blocks separated by \\n\\n,\n//     which the downstream text chunker can split at block boundaries.\nfunc jsonToMarkdown(data []byte) (string, error) {\n\tdata = trimBOM(data)\n\tif len(data) == 0 {\n\t\treturn \"\", fmt.Errorf(\"empty JSON content\")\n\t}\n\tif !json.Valid(data) {\n\t\treturn \"\", fmt.Errorf(\"invalid JSON content\")\n\t}\n\n\tvar parsed interface{}\n\tif err := json.Unmarshal(data, &parsed); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse JSON: %w\", err)\n\t}\n\n\t// Normalize: convert top-level arrays to index-keyed dicts\n\tnormalized := listToDictPreprocess(parsed)\n\n\t// If the whole thing fits in one chunk, just format it\n\twholeSize := jsonSize(normalized)\n\tif wholeSize <= defaultJSONChunkSize {\n\t\tformatted := formatValue(normalized)\n\t\treturn wrapCodeBlock(formatted), nil","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/infrastructure/docparser/json_converter.go#L14-L50","documentation":"jsonToMarkdown first trims a UTF-8 BOM and then requires at least one byte of input; a zero-length payload is rejected with \"empty JSON content\" before any validation. The converter only accepts non-empty JSON documents because there is nothing to render into markdown chunks.","triggerScenarios":"Read (json_converter) invoked with an empty file, an empty reader, or a document whose bytes were entirely consumed/trimmed (e.g. a file containing only a BOM).","commonSituations":"Zero-byte .json file from a failed export or interrupted download; empty request body passed to the parser; upstream extraction step produced no output; file containing only a BOM.","solutions":["Check the input file size with ls/stat; regenerate or re-export the JSON so it has content.","Ensure the upstream producer finished writing before Read is called (check for partial writes/interrupted downloads).","Verify you are pointing the parser at the correct file path and not an empty placeholder."],"exampleFix":"// before\n$ wc -c data.json\n0 data.json\n// after: re-export so the file has real JSON content\n$ wc -c data.json\n142 data.json","handlingStrategy":"validation","validationCode":"info, err := os.Stat(path)\nif err != nil { return err }\nif info.Size() == 0 {\n    return fmt.Errorf(\"refusing to parse empty JSON file %s\", path)\n}","typeGuard":null,"tryCatchPattern":"md, err := converter.Read(ctx, req)\nif err != nil {\n    if strings.Contains(err.Error(), \"empty JSON content\") {\n        return fmt.Errorf(\"input %s is empty; regenerate the JSON export before parsing\", req.Path)\n    }\n    return err\n}","preventionTips":["Check file size > 0 before handing files to the parser.","Make upstream exports atomic (write to temp file, then rename) so partial/empty files never appear.","Alert on zero-byte files produced by your export jobs."],"tags":["json","validation","empty-input"],"backgroundTag":"empty-json-content","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}