> For the complete documentation index, see [llms.txt](https://nomadamas.gitbook.io/ragchain-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nomadamas.gitbook.io/ragchain-docs/utils/linker/json_linker.md).

# Json Linker

## Overview

`JsonLinker` is a singleton class that allows the role of a linker to be played locally to use JSON file without using an external DB like redisDB or dynamoDB.

The class manages JSON files. It is used to link database and passage IDs that are stored in retrievals. The class is part of the `RAGchain` project and is located in the `RAGchain/utils/linker/json_linker.py` file.

The class inherits from the BaseLinker class and implements the put\_json, get\_json, and flush\_db abstract methods.

The class uses the `json` Python library to interact with a JSON file. It requires the `JSON_LINKER_PATH` environment variable to be set, which specifies the path to the JSON file.

## Usage

To use the `JsonLinker` class, you first need to set the required environment variable `LINKER_TYPE`and `JSON_LINKER_PATH`.

```
LINKER_TYPE="json"
JSON_LINKER_PATH="json file path(name)"
```

Here is an example of how to use the `JsonLinker` class:

```Python
from RAGchain.utils.linker import JsonLinker

# Create an instance of the JsonLinker class
linker = JsonLinker()

# Check the connection to the Json database
if linker.connection_check():
    print("Connected to Json database")

# Put JSON data into the Json database
linker.put_json("1234", {"name": "John", "age": 30})

# Get JSON data from the Json database
data = linker.get_json(["1234"])
print(data)

# Flush the Json database
linker.flush_db()
```

Please note that the `put_json` method requires a unique ID and a JSON data as parameters. The `get_json` method requires a list of IDs as a parameter. The `flush_db` method does not require any parameters.
