feat: enhance JsonListChunker with nested JSON support, json_path selector, and parent context - #4674
Open
AdriDob wants to merge 1 commit into
Open
feat: enhance JsonListChunker with nested JSON support, json_path selector, and parent context#4674AdriDob wants to merge 1 commit into
AdriDob wants to merge 1 commit into
Conversation
…ector, and parent context - Add recursive JSON array discovery (find_json_arrays) - Add json_path selector for explicit array targeting - Add auto-detection of nested arrays with multi-array error handling - Add parent_context metadata extraction from all ancestor levels - Add json_path metadata per chunk (e.g., 'records.items[0]') - Add parent_context metadata with sibling values from all ancestor levels - Support class-level defaults and per-document metadata overrides - Add comprehensive test suite (18 tests) Fixes topoteretes#4236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The current JsonListChunker only handles flat JSON lists at the root level (e.g.,
[{...}, {...}]). Many real-world JSON APIs return nested structures like{"records": {"items": [...]}}which the chunker silently fails to process.Solution
Enhanced JsonListChunker with full nested JSON support:
New Features
Recursive JSON Array Discovery (
find_json_arrays): Recursively finds all arrays in nested JSON structuresExplicit
json_pathSelector: Target a specific nested array using JSONPath syntax (e.g.,"records.items"or"$.records.items")Auto-Detection with Multi-Array Safety: When no
json_pathprovided, auto-detects nested arrays. If multiple arrays found, raises clear error asking user to specify which one.json_pathMetadata Per Chunk: Each chunk getsjson_pathmetadata (e.g.,"records.items[0]") for traceabilityParent Context Metadata: Extracts sibling simple values from all ancestor levels (e.g.,
batch_idat root level carried to chunks from$.records.items)Flexible Configuration:
JsonListChunker.json_path,JsonListChunker.auto_detect)document.metadata(e.g.,{"json_path": "$.records.items"})Explicit
json_pathOverrides Auto-Detect: Explicit path takes precedence, enabling targeted selection in multi-array documentsConfiguration Options
json_path"records.items")auto_detectBackward Compatibility
Tests
Added 18 comprehensive tests covering:
Related
Fixes #4236
Related to PRs #4254, #4511