mirror of
https://github.com/hwchase17/langchain
synced 2024-10-31 15:20:26 +00:00
6567b73e1a
This implements a loader of text passages in JSON format. The `jq` syntax is used to define a schema for accessing the relevant contents from the JSON file. This requires dependency on the `jq` package: https://pypi.org/project/jq/. --------- Signed-off-by: Aivin V. Solatorio <avsolatorio@gmail.com>
17 lines
499 B
Python
17 lines
499 B
Python
from pathlib import Path
|
|
|
|
from langchain.document_loaders import JSONLoader
|
|
|
|
|
|
def test_json_loader() -> None:
|
|
"""Test unstructured loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/example.json"
|
|
loader = JSONLoader(str(file_path), ".messages[].content")
|
|
docs = loader.load()
|
|
|
|
# Check that the correct number of documents are loaded.
|
|
assert len(docs) == 3
|
|
|
|
# Make sure that None content are converted to empty strings.
|
|
assert docs[-1].page_content == ""
|