DS DevShelfHub Projects · AI tools
Tutorials / CrewAI / Reference / Classes / JSONKnowledgeSource
Class knowledge

JSONKnowledgeSource: Reference Guide

By DevShelfHub

Loads JSON documents into the knowledge store.

See the CrewAI API reference index, CrewAI introduction, and core concepts for surrounding context.

What is JSONKnowledgeSource?

JSONKnowledgeSource ingests structured files — either a single JSON object or an array of objects — into the same embedding + retrieval pipeline CrewAI uses for PDFs and Markdown. Each logical record becomes its own retrievable chunk, which is ideal for machine-generated exports (OpenAPI specs, feature-flag dumps, CRM snapshots) where rows already carry stable identifiers you want agents to cite.

Shape matters more than with prose files: deeply nested trees can explode into giant serialized blobs per chunk, while flat arrays of small objects behave predictably in vector search. Normalize large documents into an array of {id, title, body} objects before embedding so similarity scores map to human-meaningful units. Refresh strategy is file-based — when the JSON on disk changes, plan a reload or crew restart policy so agents do not answer from stale vectors silently.

Security review is still required: JSON exports often include secrets or PII in string fields. Scrub before pointing agents at the path, and scope JSONKnowledgeSource to the smallest crew or agent that needs it.

When to Use

Structured exports, API dumps.

Use Cases

  • API exports
  • Configuration dumps

Key Features

  • JSON-native

When NOT to Use

Free-form prose — use Text or PDF.

Notes

Chunk size vs nesting

Huge nested objects embed as monolithic vectors — flatten or split arrays so retrieval returns focused snippets instead of entire configs.

Embedder alignment

Use the same embedder as other knowledge sources; mixed dimensions make retrieval silently useless.

Staleness

File edits do not auto-refresh every vector backend. Version exports and bump sources when content changes materially.

Secrets in JSON

Strip tokens and emails before ingestion; agents will happily quote them back to users.

Import

python
from crewai.knowledge.source.json_knowledge_source import JSONKnowledgeSource

Key Parameters

Parameter Type Default Purpose
file_path str JSON path.

Code Examples

Array of policy objects

python
from crewai.knowledge.source.json_knowledge_source import JSONKnowledgeSource

src = JSONKnowledgeSource(file_path='policies/features.json')

Attach at crew level

python
from crewai import Crew

src = JSONKnowledgeSource(file_path='exports/tickets.json')

crew = Crew(agents=[support], tasks=[triage], knowledge_sources=[src], verbose=True)

Specialist agent-only knowledge

python
from crewai import Agent

agent = Agent(
    role='Config analyst',
    goal='Answer using JSON exports',
    backstory='Never invent keys.',
    knowledge_sources=[JSONKnowledgeSource(file_path='config_dump.json')],
)

Common Mistakes

❌ Feeding unbounded API dumps

✅ Pre-filter to the rows relevant to the crew to control embedding cost.

JSONKnowledgeSource FAQ

What is JSONKnowledgeSource in CrewAI?

Loads JSON documents into the knowledge store. JSONKnowledgeSource ingests structured files — either a single JSON object or an array of objects — into the same embedding + retrieval pipeline CrewAI uses for PDFs and Markdown. Each logical record becomes its own retrievable chunk, which is ideal for machine-generated exports (OpenAPI specs, feature-flag dumps, CRM snapshots) where rows already carry stable identifiers you want agents to cite. Shape matters more than with prose files: deeply nested trees can explode into …

Which package defines the CrewAI class JSONKnowledgeSource?

DevShelfHub maps JSONKnowledgeSource to Python module crewai.knowledge.source (package path crewai.knowledge.source in this reference). Pin your installed crewai version and match imports to the snippet on this page.

When should I use JSONKnowledgeSource?

Structured exports, API dumps.

When should I avoid using JSONKnowledgeSource?

Free-form prose — use Text or PDF.

How do I import JSONKnowledgeSource in Python?

from crewai.knowledge.source.json_knowledge_source import JSONKnowledgeSource

Where can I explore more CrewAI API reference pages?

Open the CrewAI API reference index on DevShelfHub to search 58 classes, 30 methods, and 16 decorators, each with runnable examples, parameters, common mistakes, and cross-links.