Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

JSONConverter

Convert JSON files into documents your pipelines can query.

Key Features

  • Filters JSON content using jq filter syntax to extract specific fields.
  • Configurable content key to select which JSON field becomes the document content.
  • Optional extraction of additional metadata fields from the JSON source.
  • Optional metadata attachment to resulting documents.

Configuration

  1. Drag the JSONConverter component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. Configure the component settings:
    • Set the JQ Schema to filter the JSON source and extract only specific parts. For information on the filter syntax, see the jq documentation. If not specified, the whole JSON file is used.
    • Set the Content Key to specify which key from the extracted object becomes the document's content. You must set either jq_schema, content_key, or both.
    • Set Extra Meta Fields to specify additional keys to extract as document metadata from the filtered JSON.
    • Set Store Full Path to control whether the full file path or just the file name is stored in document metadata.

Connections

JSONConverter accepts a list of file paths or ByteStream objects through its sources input. It outputs a list of Document objects.

It typically connects with:

  • FileTypeRouter: receives JSON files routed by MIME type.
  • DocumentJoiner: sends converted documents to join with output from other converters before further processing.

Source Code

To check this component's source code, open json.py in the Haystack repository.

Usage Examples

Basic Configuration

  JSONConverter:
type: haystack.components.converters.json.JSONConverter
init_parameters:
store_full_path: false

Using the Component in an Index

In this index, JSONConverter receives JSON files from FileTypeRouter and sends them to DocumentJoiner that combines documents from different converters.

# haystack-pipeline
components:
FileTypeRouter:
type: haystack.components.routers.file_type_router.FileTypeRouter
init_parameters:
mime_types:
- text/text
- text/markdown
- application/json
additional_mimetypes:
TextFileToDocument:
type: haystack.components.converters.txt.TextFileToDocument
init_parameters:
encoding: utf-8
store_full_path: false
MarkdownToDocument:
type: haystack.components.converters.markdown.MarkdownToDocument
init_parameters:
table_to_single_line: false
progress_bar: true
store_full_path: false
DocumentJoiner:
type: haystack.components.joiners.document_joiner.DocumentJoiner
init_parameters:
join_mode: concatenate
weights:
top_k:
sort_by_score: true
DocumentSplitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: word
split_length: 200
split_overlap: 0
split_threshold: 0
splitting_function:
respect_sentence_boundary: false
language: en
use_split_rules: true
extend_abbreviations: true
DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
policy: NONE
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: aga-index
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
JSONConverter:
type: haystack.components.converters.json.JSONConverter
init_parameters:
jq_schema:
content_key:
extra_meta_fields:
store_full_path: false

connections:
- sender: FileTypeRouter.text/text
receiver: TextFileToDocument.sources
- sender: FileTypeRouter.text/markdown
receiver: MarkdownToDocument.sources
- sender: TextFileToDocument.documents
receiver: DocumentJoiner.documents
- sender: MarkdownToDocument.documents
receiver: DocumentJoiner.documents
- sender: DocumentJoiner.documents
receiver: DocumentSplitter.documents
- sender: DocumentSplitter.documents
receiver: DocumentWriter.documents

- sender: FileTypeRouter.application/json
receiver: JSONConverter.sources
- sender: JSONConverter.documents
receiver: DocumentJoiner.documents

max_runs_per_component: 100

metadata: {}

inputs:
files:
- FileTypeRouter.sources

Parameters

Inputs

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]A list of file paths or ByteStream objects to convert.
metaOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional metadata to attach to the documents. This value can be either a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced documents. If it's a list, the length of the list must match the number of sources. If sources contain ByteStream objects, their meta will be added to the output documents.

Outputs

ParameterTypeDescription
documentsList[Document]A list of created documents.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
jq_schemaOptional[str]NoneOptional jq filter string to extract content. If not specified, the whole JSON object will be used to extract information.
content_keyOptional[str]NoneOptional key to extract document content. If jq_schema is specified, the content_key will be extracted from that object.
extra_meta_fieldsOptional[Union[Set[str], Literal['*']]]NoneAn optional set of meta keys to extract from the content. If jq_schema is specified, all keys will be extracted from that object.
store_full_pathboolFalseIf True, the full path of the file is stored in the metadata of the document. If False, only the file name is stored.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
sourcesList[Union[str, Path, ByteStream]]A list of file paths or ByteStream objects to convert.
metaOptional[Union[Dict[str, Any], List[Dict[str, Any]]]]NoneOptional metadata to attach to the documents. This value can be either a list of dictionaries or a single dictionary. If it's a single dictionary, its content is added to the metadata of all produced documents. If it's a list, the length of the list must match the number of sources. If sources contain ByteStream objects, their meta will be added to the output documents.