Skip to main content

JSONLines 文件

¥JSONLines files

本示例介绍如何从 JSONLines 或 JSONL 文件加载数据。第二个参数是一个 JSONPointer,指向文件中每个 JSON 对象要提取的属性。将为文件中的每个 JSON 对象创建一个文档。

¥This example goes over how to load data from JSONLines or JSONL files. The second argument is a JSONPointer to the property to extract from each JSON object in the file. One document will be created for each JSON object in the file.

JSONLines 文件示例:

¥Example JSONLines file:

{"html": "This is a sentence."} {"html": "This is another sentence."}

代码示例:

¥Example code:

import { JSONLinesLoader } from "langchain/document_loaders/fs/json";

const loader = new JSONLinesLoader(
"src/document_loaders/example_data/example.jsonl",
"/html"
);

const docs = await loader.load();
/*
[
Document {
"metadata": {
"blobType": "application/jsonl+json",
"line": 1,
"source": "blob",
},
"pageContent": "This is a sentence.",
},
Document {
"metadata": {
"blobType": "application/jsonl+json",
"line": 2,
"source": "blob",
},
"pageContent": "This is another sentence.",
},
]
*/