> ## Documentation Index
> Fetch the complete documentation index at: https://docs.upsonic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON Splitter

> Split JSON documents using structure-aware recursive traversal

## Overview

JSON splitter operates on parsed JSON data, traversing the JSON graph to create chunks that are valid, self-contained JSON objects. Provides path-aware traceability by adding JSON paths to chunk metadata. Falls back to text chunking if JSON parsing fails.

**Splitter Class:** `JSONChunker`

**Config Class:** `JSONChunkingConfig`

## Dependencies

No additional dependencies required. Uses standard library.

## Examples

```python theme={null}
from upsonic import Agent, Task, KnowledgeBase
from upsonic.loaders.json import JSONLoader
from upsonic.loaders.config import JSONLoaderConfig
from upsonic.embeddings import OpenAIEmbedding, OpenAIEmbeddingConfig
from upsonic.text_splitter.json_chunker import JSONChunker, JSONChunkingConfig
from upsonic.vectordb import ChromaProvider, ChromaConfig, ConnectionConfig, Mode

# Configure splitter
splitter_config = JSONChunkingConfig(
    chunk_size=512,
    chunk_overlap=50,
    convert_lists_to_dicts=True,
    max_depth=50
)
splitter = JSONChunker(splitter_config)

# Setup KnowledgeBase
loader = JSONLoader(JSONLoaderConfig())
embedding = OpenAIEmbedding(OpenAIEmbeddingConfig())
vectordb = ChromaProvider(ChromaConfig(
    collection_name="json_docs",
    vector_size=1536,
    connection=ConnectionConfig(mode=Mode.IN_MEMORY)
))

kb = KnowledgeBase(
    sources=["data.json"],
    embedding_provider=embedding,
    vectordb=vectordb,
    loaders=[loader],
    splitters=[splitter]
)

# Query with Agent
agent = Agent("anthropic/claude-sonnet-4-5")
task = Task("Find all user records", context=[kb])
result = agent.do(task)
print(result)
```

## Parameters

| Parameter | Type | Description | Default | Source |
| - | - | - | - | - |
| `chunk_size` | `int` | Target size of each chunk | 1024 | Base |
| `chunk_overlap` | `int` | Overlapping units between chunks | 200 | Base |
| `min_chunk_size` | `int \| None` | Minimum size for a chunk | None | Base |
| `length_function` | `Callable[[str], int]` | Function to measure text length | `len` | Base |
| `strip_whitespace` | `bool` | Strip leading/trailing whitespace | False | Base |
| `convert_lists_to_dicts` | `bool` | Convert lists to dict-like objects | True | Specific |
| `max_depth` | `int \| None` | Maximum recursion depth | 50 | Specific |
| `json_encoder_options` | `dict` | Options for json.dumps | {} | Specific |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.