langchain_community.document_loaders.json_loader.JSONLoader

class langchain_community.document_loaders.json_loader.JSONLoader(file_path: Union[str, Path], jq_schema: str, content_key: Optional[str] = None, metadata_func: Optional[Callable[[Dict, Dict], Dict]] = None, text_content: bool = True, json_lines: bool = False)[source]

Load a JSON file using a jq schema.

Example

[{“text”: …}, {“text”: …}, {“text”: …}] -> schema = .[].text {“key”: [{“text”: …}, {“text”: …}, {“text”: …}]} -> schema = .key[].text [“”, “”, “”] -> schema = .[]

Initialize the JSONLoader.

Parameters
  • file_path (Union[str, Path]) – 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).

  • 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.

Methods

__init__(file_path, jq_schema[, ...])

Initialize the JSONLoader.

lazy_load()

A lazy loader for Documents.

load()

Load and return documents from the JSON file.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(file_path: Union[str, Path], jq_schema: str, content_key: Optional[str] = None, metadata_func: Optional[Callable[[Dict, Dict], Dict]] = None, text_content: bool = True, json_lines: bool = False)[source]

Initialize the JSONLoader.

Parameters
  • file_path (Union[str, Path]) – 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).

  • 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.

lazy_load() Iterator[Document]

A lazy loader for Documents.

load() List[Document][source]

Load and return documents from the JSON file.

load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document]

Load Documents and split into chunks. Chunks are returned as Documents.

Parameters

text_splitter – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns

List of Documents.