Code
examples/basics/knowledge/concepts/readers/overview/json_reader.py
Usage
1
Set up your virtual environment
2
Install dependencies
3
Set environment variables
4
Run Agent
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
import json
from pathlib import Path
from agno.knowledge.reader.json_reader import JSONReader
reader = JSONReader()
json_path = Path("tmp/test.json")
test_data = {"key": "value"}
json_path.write_text(json.dumps(test_data))
try:
print("Starting read...")
documents = reader.read(json_path)
if documents:
for doc in documents:
print(doc.name)
print(doc.content)
print(f"Content length: {len(doc.content)}")
print("-" * 80)
else:
print("No documents were returned")
except Exception as e:
print(f"Error type: {type(e)}")
print(f"Error occurred: {str(e)}")
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Set environment variables
export OPENAI_API_KEY=xxx
Run Agent
python examples/basics/knowledge/concepts/readers/overview/json_reader.py
python examples/basics/knowledge/concepts/readers/overview/json_reader.py
| Parameter | Type | Default | Description |
|---|---|---|---|
path | Path | Required | Path to JSON file to read |
chunk | bool | False | Whether to chunk the documents (overrides base Reader default) |
Was this page helpful?