Tencent/WeKnora · error

empty JSON content

Error message

empty JSON content

What it means

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.

Source

Thrown at internal/infrastructure/docparser/json_converter.go:32

const defaultJSONChunkSize = 1536

// minJSONChunkSize is the minimum chunk size. A new chunk is only started
// when the current chunk has reached at least this size.
var minJSONChunkSize = defaultJSONChunkSize - 200

// jsonToMarkdown converts raw JSON bytes into markdown text
//
// Key properties:
//   - Every output chunk is a **valid JSON object** (not a fragment).
//   - Nested paths from root to leaf are **fully preserved** in each chunk.
//   - Arrays are converted to index-keyed dicts so the algorithm is uniform.
//   - Small objects that fit within maxChunkSize are kept intact (not split).
//   - The output is a series of fenced ```json code blocks separated by \n\n,
//     which the downstream text chunker can split at block boundaries.
func jsonToMarkdown(data []byte) (string, error) {
	data = trimBOM(data)
	if len(data) == 0 {
		return "", fmt.Errorf("empty JSON content")
	}
	if !json.Valid(data) {
		return "", fmt.Errorf("invalid JSON content")
	}

	var parsed interface{}
	if err := json.Unmarshal(data, &parsed); err != nil {
		return "", fmt.Errorf("failed to parse JSON: %w", err)
	}

	// Normalize: convert top-level arrays to index-keyed dicts
	normalized := listToDictPreprocess(parsed)

	// If the whole thing fits in one chunk, just format it
	wholeSize := jsonSize(normalized)
	if wholeSize <= defaultJSONChunkSize {
		formatted := formatValue(normalized)
		return wrapCodeBlock(formatted), nil

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the input file size with ls/stat; regenerate or re-export the JSON so it has content.
  2. Ensure the upstream producer finished writing before Read is called (check for partial writes/interrupted downloads).
  3. Verify you are pointing the parser at the correct file path and not an empty placeholder.

Example fix

// before
$ wc -c data.json
0 data.json
// after: re-export so the file has real JSON content
$ wc -c data.json
142 data.json
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(path)
if err != nil { return err }
if info.Size() == 0 {
    return fmt.Errorf("refusing to parse empty JSON file %s", path)
}

Try / catch

md, err := converter.Read(ctx, req)
if err != nil {
    if strings.Contains(err.Error(), "empty JSON content") {
        return fmt.Errorf("input %s is empty; regenerate the JSON export before parsing", req.Path)
    }
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/e2feb9f71cb55ee5. Report an issue: GitHub.