JSONLoaderExecuteNTimes
Python template · sinapsis_langchain_readers.templates.langchain_data_readers
Overview
Dynamic Template to load documents from Langchain document_loaders module The template loads the document either as a Document object in the generic_data field of DataContainer of each string as a TextPacket if add_document_as_text_packet is set as True
JSONLoader — inherited documentation
Load a `JSON` file using a `jq` schema.
Setup: .. code-block:: bash
pip install -U jq
Instantiate: .. code-block:: python
from langchain_community.document_loaders import JSONLoader import json from pathlib import Path
file_path='./sample_quiz.json' data = json.loads(Path(file_path).read_text()) loader = JSONLoader( file_path=file_path, jq_schema='.quiz', text_content=False)
Load: .. code-block:: python
docs = loader.load() print(docs[0].page_content[:100]) print(docs[0].metadata)
.. code-block:: python
{"sport": {"q1": {"question": "Which one is correct team name in NBA?", "options": ["New York Bulls" {'source': '/sample_quiz .json', 'seq_num': 1}
Async load: .. code-block:: python
docs = await loader.aload() print(docs[0].page_content[:100]) print(docs[0].metadata)
.. code-block:: python
{"sport": {"q1": {"question": "Which one is correct team name in NBA?", "options": ["New York Bulls" {'source': '/sample_quizg .json', 'seq_num': 1}
Lazy load: .. code-block:: python
docs = [] docs_lazy = loader.lazy_load()
# async variant: # docs_lazy = await loader.alazy_load()
for doc in docs_lazy: docs.append(doc) print(docs[0].page_content[:100]) print(docs[0].metadata)
.. code-block:: python
{"sport": {"q1": {"question": "Which one is correct team name in NBA?", "options": ["New York Bulls" {'source': '/sample_quiz .json', 'seq_num': 1}Initialize the JSONLoader.
Args: file_path (Union[str, PathLike]): The path to the JSON or JSON Lines file. jq_schema (str): The jq schema to use to extract the data or text from the JSON. content_key (str): The key to use to extract the content from the JSON if the jq_schema results to a list of objects (dict). If is_content_key_jq_parsable is True, this has to be a jq compatible schema. If is_content_key_jq_parsable is False, this should be a simple string key. is_content_key_jq_parsable (bool): A flag to determine if content_key is parsable by jq or not. If True, content_key is treated as a jq schema and compiled accordingly. If False or if content_key is None, content_key is used as a simple string. Default is False. metadata_func (Callable[Dict, Dict]): A function that takes in the JSON object extracted by the jq_schema and the default metadata and returns a dict of the updated metadata. text_content (bool): Boolean flag to indicate whether the content is in string format, default to True. json_lines (bool): Boolean flag to indicate whether the input is in JSON Lines format.
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis_langchain_readers==1.0.0uv pip install sinapsis_langchain_readers==1.0.0uv add sinapsis_langchain_readers==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Required
Default: null
Optional
Default: null
Optional
Default: null
Optional
Default: false
Optional
Default: null
Optional
Default: true
Optional
Default: null
Optional
Default: false
Optional
Default: 1
Optional
Default: false
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "JSONLoaderExecuteNTimes"
class_name: "JSONLoaderExecuteNTimes"
attributes:
jsonloader_init:
file_path: null
jq_schema: null
json_lines: false
content_key: null
text_content: true
metadata_func: null
is_content_key_jq_parsable: false
n_times_execute: 1
add_document_as_text_packet: false
View original docstring example
The source example references WikipediaLoaderWrapper, not JSONLoaderExecuteNTimes.
agent:
name: my_test_agent
templates:
- template_name: InputTemplate
class_name: InputTemplate
attributes: {}
- template_name: WikipediaLoaderWrapper
class_name: WikipediaLoaderWrapper ## note that because it is a dynamic template,
template_input: InputTemplate ## the class name depends on the actual class that is used.
attributes:
add_document_as_text_packet: false
wikipedialoader_init:
query: the query for wikipedia
lang: en
load_max_docs: 5000
load_all_available_meta: False
doc_content_chars_max: 4000,
n_times_execute determines the number of times the template's execute
method is called. By default, it only gets called once. Further calls
to execute are bypassed.Inheritance
sinapsis_langchain_readers.templates.langchain_data_readers.ExecuteNTimesLangchainDataReadersEnvironment variables
Environment definitions belong to their canonical Python modules.