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.Example JSON file:
Copy
{ "texts": ["This is a sentence.", "This is another sentence."], "nestedTexts": { "one": "This is a sentence nested in an object.", "two": "This is another sentence nested in an object." }}
Example code:
Copy
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 { pageContent: 'This is a sentence.', metadata: { source: 'example.json', line: 1 } }, Document { pageContent: 'This is another sentence.', metadata: { source: 'example.json', line: 2 } }, Document { pageContent: 'This is a sentence nested in an object.', metadata: { source: 'example.json', line: 3 } }, Document { pageContent: 'This is another sentence nested in an object.', metadata: { source: 'example.json', line: 4 } }]*/
You can choose which keys in your JSON object you want to extract strings from.In this example, we want to only extract information from “from” and “surname” entries.