*   [](/v0.2/)
*   [How-to guides](/v0.2/docs/how_to/)
*   How to load JSON data

On this page

How to load JSON data
=====================

> [JSON (JavaScript Object Notation)](https://en.wikipedia.org/wiki/JSON) is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and arrays (or other serializable values).

> [JSON Lines](https://jsonlines.org/) is a file format where each line is a valid JSON value.

The JSON loader uses [JSON pointer](https://github.com/janl/node-jsonpointer) to target keys in your JSON files you want to target.

### No JSON pointer example[​](#no-json-pointer-example "Direct link to No JSON pointer example")

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:

    {  "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.",  },]*/

### Using JSON pointer example[​](#using-json-pointer-example "Direct link to Using JSON pointer example")

You can do a more advanced scenario by choosing which keys in your JSON object you want to extract string from.

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 {    pageContent: 'LinkedIn Job',    metadata: { source: './src/json/example.json', line: 1 }  },  Document {    pageContent: 'LinkedIn Job2',    metadata: { source: './src/json/example.json', line: 2 }  },  Document {    pageContent: 'bob',    metadata: { source: './src/json/example.json', line: 3 }  }]**/

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchainjs/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

How to load PDF files

](/v0.2/docs/how_to/document_loader_pdf)[

Next

How to combine results from multiple retrievers

](/v0.2/docs/how_to/ensemble_retriever)

*   [No JSON pointer example](#no-json-pointer-example)
*   [Using JSON pointer example](#using-json-pointer-example)