RecursiveJsonSplitter#
- class langchain_text_splitters.json.RecursiveJsonSplitter(
- max_chunk_size: int = 2000,
- min_chunk_size: int | None = None,
Splits JSON data into smaller, structured chunks while preserving hierarchy.
This class provides methods to split JSON data into smaller dictionaries or JSON-formatted strings based on configurable maximum and minimum chunk sizes. It supports nested JSON structures, optionally converts lists into dictionaries for better chunking, and allows the creation of document objects for further use.
Initialize the chunk size configuration for text processing.
This constructor sets up the maximum and minimum chunk sizes, ensuring that the
min_chunk_size
defaults to a value slightly smaller than themax_chunk_size
if not explicitly provided.- Parameters:
max_chunk_size (int) – The maximum size for a chunk. Defaults to 2000.
min_chunk_size (int) – The minimum size for a chunk. If None, defaults to the maximum chunk size minus 200, with a lower bound of 50.
Attributes
max_chunk_size
The maximum size for each chunk.
min_chunk_size
The minimum size for each chunk, derived from
max_chunk_size
if not explicitly provided.Methods
__init__
([max_chunk_size, min_chunk_size])Initialize the chunk size configuration for text processing.
create_documents
(texts[, convert_lists, ...])Create documents from a list of json objects (Dict).
split_json
(json_data[, convert_lists])Splits JSON into a list of JSON chunks.
split_text
(json_data[, convert_lists, ...])Splits JSON into a list of JSON formatted strings.
- __init__(
- max_chunk_size: int = 2000,
- min_chunk_size: int | None = None,
Initialize the chunk size configuration for text processing.
This constructor sets up the maximum and minimum chunk sizes, ensuring that the
min_chunk_size
defaults to a value slightly smaller than themax_chunk_size
if not explicitly provided.- Parameters:
max_chunk_size (int) – The maximum size for a chunk. Defaults to 2000.
min_chunk_size (int | None) – The minimum size for a chunk. If None, defaults to the maximum chunk size minus 200, with a lower bound of 50.
- Return type:
None
- create_documents(
- texts: list[dict[str, Any]],
- convert_lists: bool = False,
- ensure_ascii: bool = True,
- metadatas: list[dict[Any, Any]] | None = None,
Create documents from a list of json objects (Dict).
- Parameters:
texts (list[dict[str, Any]])
convert_lists (bool)
ensure_ascii (bool)
metadatas (list[dict[Any, Any]] | None)
- Return type:
list[Document]
Examples using RecursiveJsonSplitter