JSON 文件
¥JSON files
JSON 加载器使用 JSON 指针 来定位你想要定位的 JSON 文件中的键。
¥The JSON loader use JSON pointer to target keys in your JSON files you want to target.
无 JSON 指针示例
¥No JSON pointer example
最简单的使用方法是不指定 JSON 指针。加载器将加载它在 JSON 对象中找到的所有字符串。
¥The most simple way of using it, is to specify no JSON pointer. The loader will load all strings it finds in the JSON object.
JSON 文件示例:
¥Example JSON file:
{
"texts": ["This is a sentence.", "This is another sentence."]
}
代码示例:
¥Example code:
import { JSONLoader } from "langchain/document_loaders/fs/json";
const loader = new JSONLoader("src/document_loaders/example_data/example.json");
const docs = await loader.load();
/*
[
Document {
"metadata": {
"blobType": "application/json",
"line": 1,
"source": "blob",
},
"pageContent": "This is a sentence.",
},
Document {
"metadata": {
"blobType": "application/json",
"line": 2,
"source": "blob",
},
"pageContent": "This is another sentence.",
},
]
*/
使用 JSON 指针示例
¥Using JSON pointer example
你可以通过选择要从 JSON 对象中提取字符串的键来实现更高级的场景。
¥You can do a more advanced scenario by choosing which keys in your JSON object you want to extract string from.
在本例中,我们只想从 "from" 和 "surname" 条目中提取信息。
¥In this example, we want to only extract information from "from" and "surname" entries.
{
"1": {
"body": "BD 2023 SUMMER",
"from": "LinkedIn Job",
"labels": ["IMPORTANT", "CATEGORY_UPDATES", "INBOX"]
},
"2": {
"body": "Intern, Treasury and other roles are available",
"from": "LinkedIn Job2",
"labels": ["IMPORTANT"],
"other": {
"name": "plop",
"surname": "bob"
}
}
}
代码示例:
¥Example code:
import { JSONLoader } from "langchain/document_loaders/fs/json";
const loader = new JSONLoader(
"src/document_loaders/example_data/example.json",
["/from", "/surname"]
);
const docs = await loader.load();
/*
[
Document {
"metadata": {
"blobType": "application/json",
"line": 1,
"source": "blob",
},
"pageContent": "BD 2023 SUMMER",
},
Document {
"metadata": {
"blobType": "application/json",
"line": 2,
"source": "blob",
},
"pageContent": "LinkedIn Job",
},
...
]