- TODO: Add any other relevant links, like information about underlying API, etc.
Overview
Integration details
Class | Package | Local | Serializable | JS support |
---|---|---|---|---|
JSONLoader | langchain-community | ✅ | ❌ | ✅ |
Loader features
Source | Document Lazy Loading | Native Async Support |
---|---|---|
JSONLoader | ✅ | ❌ |
Setup
To access JSON document loader you’ll need to install thelangchain-community
integration package as well as the jq
python package.
Credentials
No credentials are required to use theJSONLoader
class.
To enable automated tracing of your model calls, set your LangSmith API key:
Installation
Install langchain-community and jq:Initialization
Now we can instantiate our model object and load documents:- TODO: Update model instantiation with relevant params.
Load
Lazy Load
Read from JSON Lines file
If you want to load documents from a JSON Lines file, you passjson_lines=True
and specify jq_schema
to extract page_content
from a single JSON object.
Read specific content keys
Another option is to setjq_schema='.'
and provide a content_key
in order to only load specific content:
JSON file with jq schema content_key
To load documents from a JSON file using the content_key
within the jq schema, set is_content_key_jq_parsable=True
. Ensure that content_key
is compatible and can be parsed using the jq schema.
Extracting metadata
Generally, we want to include metadata available in the JSON file into the documents that we create from the content. The following demonstrates how metadata can be extracted using theJSONLoader
.
There are some key changes to be noted. In the previous example where we didn’t collect the metadata, we managed to directly specify in the schema where the value for the page_content
can be extracted from.
In this example, we have to tell the loader to iterate over the records in the messages
field. The jq_schema then has to be .messages[]
This allows us to pass the records (dict) into the metadata_func
that has to be implemented. The metadata_func
is responsible for identifying which pieces of information in the record should be included in the metadata stored in the final Document
object.
Additionally, we now have to explicitly specify in the loader, via the content_key
argument, the key from the record where the value for the page_content
needs to be extracted from.