> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.storages.key value storages.json

<a id="camel.storages.key_value_storages.json" />

<a id="camel.storages.key_value_storages.json.CamelJSONEncoder" />

## CamelJSONEncoder

```python theme={"system"}
class CamelJSONEncoder(JSONEncoder):
```

A custom JSON encoder for serializing CAMEL-specific types.

Handles serialization of:

* Enumerated types (RoleType, TaskType, ModelType, OpenAIBackendRole)
* Pydantic BaseModel objects (from structured outputs)

Ensures these types can be stored in and retrieved from JSON format.

<a id="camel.storages.key_value_storages.json.CamelJSONEncoder.default" />

### default

```python theme={"system"}
def default(self, obj):
```

<a id="camel.storages.key_value_storages.json.JsonStorage" />

## JsonStorage

```python theme={"system"}
class JsonStorage(BaseKeyValueStorage):
```

A concrete implementation of the :obj:`BaseKeyValueStorage` using JSON
files. Allows for persistent storage of records in a human-readable format.

**Parameters:**

* **path** (Path, optional): Path to the desired JSON file. If `None`, a default path `./chat_history.json` will be used. (default: :obj:`None`)

<a id="camel.storages.key_value_storages.json.JsonStorage.__init__" />

### **init**

```python theme={"system"}
def __init__(self, path: Optional[Path] = None):
```

<a id="camel.storages.key_value_storages.json.JsonStorage._json_object_hook" />

### \_json\_object\_hook

```python theme={"system"}
def _json_object_hook(self, d):
```

<a id="camel.storages.key_value_storages.json.JsonStorage.save" />

### save

```python theme={"system"}
def save(self, records: List[Dict[str, Any]]):
```

Saves a batch of records to the key-value storage system.

**Parameters:**

* **records** (List\[Dict\[str, Any]]): A list of dictionaries, where each dictionary represents a unique record to be stored.

<a id="camel.storages.key_value_storages.json.JsonStorage.load" />

### load

```python theme={"system"}
def load(self):
```

**Returns:**

List\[Dict\[str, Any]]: A list of dictionaries, where each dictionary
represents a stored record.

<a id="camel.storages.key_value_storages.json.JsonStorage.clear" />

### clear

```python theme={"system"}
def clear(self):
```

Removes all records from the key-value storage system.
