JSON
AI systems constantly exchange structured data. JSON is readable, lightweight, and works in every programming language.
JSON is a standardized form every department fills out the same way — whether you're in Python, JavaScript, or Go.
Visual Workflows
Start here — study each diagram, then use + / − to zoom if needed.
Overview
Scroll inside the frame · use + / − to zoom
Scroll inside the frame · use + / − to zoom
Key Takeaways
- 1.JSON is the universal data format for AI — every LLM request, response, tool schema, and config file uses it.
- 2.Objects {key: value}, arrays, strings, numbers, booleans, null.
- 3.Keys need double quotes.
- 4.Python uses json.dumps and json.loads.
Real Example
Scenario
You need the LLM to call a weather function with a city name.
What you would do
Define the tool schema in JSON, send it with the chat request, and the LLM returns JSON with the function name and arguments.
Practice Task
Run: python -c "import json; d={'role':'user','content':'hi'}; print(json.dumps(d))" then parse it back with json.loads. Confirm the output uses double quotes on keys.
Commands
Commands to Remember
python -c "import json; print(json.dumps({'a':1}))" # convert Python dict to JSON stringpython -c "import json; print(json.loads('{\"a\":1}'))" # parse JSON string to Python dict
Cheat Sheet
Quick recap
quick ref- •Universal format for all AI APIs — objects, arrays, strings, numbers
- •Keys must use double quotes — no trailing commas or single quotes
- •Used for LLM requests, chat messages, tool schemas, and configs
- •Python: json.dumps (object → string) · json.loads (string → object)
- •Validate structure with Pydantic or JSON Schema
- •LLMs may wrap JSON in markdown fences — strip before parsing
Common Mistakes
- ✕Not validating JSON from LLM outputs
- ✕Single quotes in JSON (invalid)
- ✕Forgetting to strip markdown fences