JSON
Read and manipulate JSON files
Overview
JSON tool allows you to read, write, and query JSON files.
The user provides JSON data; the agent parses, queries, or writes it and returns the result.
Installation
pip install "praisonai[tools]"Quick Start
- Simple Usage
python from praisonai_tools import JSONTool # Initialize json_tool = JSONTool() # Read JSON data = json_tool.read("config.json") print(data) - With Configuration
Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.
Usage with Agent
from praisonaiagents import Agent
from praisonai_tools import JSONTool
agent = Agent(
name="DataProcessor",
instructions="You help process JSON data.",
tools=[JSONTool()]
)
response = agent.chat("Read config.json and show the database settings")
print(response)Available Methods
read(path)
Read a JSON file.
from praisonai_tools import JSONTool
json_tool = JSONTool()
data = json_tool.read("data.json")write(path, data)
Write data to a JSON file.
json_tool.write("output.json", {"key": "value"})query(path, jq_query)
Query JSON with JQ-like syntax.
result = json_tool.query("data.json", ".users[0].name")How It Works
Best Practices
Validate before parsing
Handle malformed JSON gracefully so the agent returns a clear error instead of crashing.
Query by path
Extract only the fields you need rather than loading the whole document into context.
Preserve types
Keep numbers and booleans typed — don’t stringify everything when writing JSON back out.