PlantUML as a structured JSON renderer — turn config / API responses / any JSON into a tree
PlantUML’s underrated gem: render JSON / YAML as a structured tree diagram. One directive, zero boilerplate. Faster than hand-drawing Visio, cleaner than Graphviz dot, more truthful than Mermaid flowchart.
The one-liner
1 | @startjson |
Wrap a JSON block in @startjson / @endjson and PlantUML draws it as a tree. The YAML twin is @startyaml / @endyaml. Both ship in PlantUML’s official stdlib — no plugin, no extension.
What problem does this solve
Drawing “nested structure diagrams” is one of the most common documentation chores:
- Config files — package.json / tsconfig.json / nx.json / docker-compose.yml field hierarchies
- API responses — what the backend actually returned, especially when the frontend field doesn’t match
- State snapshots — dump the entire Redux store / Vuex state / Pinia store
- Domain examples — a real JSON instance conveys schema better than an ER diagram
- Test fixtures — visualize a mock payload to confirm nesting is correct
The old workflow was (a) manually re-type fields into Visio, (b) write a jq + dot script, or (c) screenshot console.log. @startjson kills (a) and (c) outright, and dramatically simplifies (b) — your script only has to assemble the JSON string, rendering is PlantUML’s job.
Full syntax: all JSON value types supported
PlantUML recognizes and renders all 6 JSON value types differently:
1 | @startjson |
Visual treatment:
- String → light background + quotes
- Number → blue
- Boolean → purple,
true/falsedistinguished null→ grey, italic- Array → expands as
<array>node with[0],[1], … children - Object → expands as
<object>node with field-name children
Highlight & styling: make the important stuff pop
Single key highlight
1 | @startjson |
The version node turns orange.
Multiple keys
1 | @startjson |
Highlight everything
1 | @startjson |
Conditional highlight (only when value matches)
1 | @startjson |
Only the deprecated node is highlighted — active: false is not. Perfect for “find all fields where enabled=false”.
Real-world example: visualizing package.json
Drop a React project’s package.json straight in:
1 | @startjson |
Paste this into a README — it’s an order of magnitude more readable than raw JSON. New team members immediately see “what’s runtime, what’s dev, what are the build commands”.
Real-world example: API response reconciliation
The actual response from your backend, dumped for debugging:
1 | @startjson |
status and the unverified email light up — at a glance: “call succeeded but the account isn’t verified”. Paste this into an issue comment; way more efficient than prose.
When JSON is huge / ugly
Pasting a 1000-line JSON straight in gets cramped. Three tricks:
1. Default truncation handles long strings
PlantUML truncates long strings in the view at 30 chars + .... The full text is still in the SVG (select-and-copy gets it back), but the diagram stays readable.
2. Vertical arrays save horizontal space
1 | @startjson |
Arrays stack vertically by default. Horizontal compact mode gets unreadable fast on big JSON — don’t.
3. Extract variables for deep nesting
1 | @startuml |
Pre-process the JSON via %json() and reference it with %$var. Avoids double-escaping hell in .puml files. The !$var = ... syntax is PlantUML’s preprocessor assignment; %json() is a stdlib helper.
JSON, YAML, JSON5 — all supported
1 | @startyaml |
@startyaml / @endyaml is JSON’s twin. YAML is more compact (no quotes, no braces) and reads cleaner when deeply nested. The output diagram is identical.
PlantUML also supports JSON5 (comments, trailing commas, single quotes) — just swap @startjson for @startjson5 / @endjson5. If your team uses .jsonc files (VSCode’s settings.json / tsconfig.json), paste them straight in.
Compared to other tools
| Tool | How you’d do the same thing | Pain point |
|---|---|---|
| Graphviz / dot | Hand-write digraph { a -> b } nodes and edges |
Tiring past 50 fields |
| Mermaid flowchart | Manually convert JSON to flowchart TD; A-->B; |
Must flatten nested structure, ugly |
| draw.io / Visio | Drag boxes + lines | Not version-controllable, no diff |
PlantUML @startjson |
Paste JSON, done | Still readable at 100+ fields |
Mermaid has no native JSON directive — you’d hand-roll a flowchart or use mindmap / sankey as approximations, neither of which is as clean.
Edge cases & gotchas
1. Escaped characters in JSON
If your JSON contains \" or \\, you do NOT need to escape them again when wrapping in @startjson — PlantUML parses it as a literal string. But if you’re using a preprocessor variable (!$var = "..."), you must double-escape.
2. Comments
PlantUML does not support comments inside @startjson / @startyaml blocks. Use ' comment outside the block.
3. Large files
Past ~500 fields, rendering slows noticeably (dot’s limit). Past that, consider (a) only diagram the subtree that matters, or (b) use jq to strip uninteresting fields before pasting.
4. Duplicate keys
JSON spec forbids duplicate keys, but PlantUML’s parser accepts them and renders only the last. Don’t let this slip past code review.
Practical workflow
1 | # 1. Pull API response |
Or paste straight into the puml.online editor — what you see is what you ship.
When NOT to use it
- Database schema evolution — ER diagram (
@startuml+entity) is clearer than a JSON instance - Class hierarchies — class diagram
- Call relations / flows — sequence or activity diagram
- The JSON structure itself is the topic —
@startjsonis perfect
Rule of thumb: “show the shape of a real data sample” → JSON diagram; “show the relationships between types” → UML diagram.
Recap
@startjson is one of PlantUML’s most under-used features:
- One directive turns any JSON / YAML into a readable tree
- All 6 JSON value types auto-styled differently
#highlightmakes important keys pop; conditional highlights for “find all X=false fields”- Real uses: config file structure, API responses, state snapshots, test fixtures
- 5-10× faster than Graphviz / Mermaid hand-rolled flowcharts
Add it to your documentation toolkit. Next time someone asks “what’s the difference between dependencies and devDependencies” — draw them a diagram instead of explaining for 10 minutes.
- Title: PlantUML as a structured JSON renderer — turn config / API responses / any JSON into a tree
- Author: puml.online
- Created at : 2026-08-04 14:00:00
- Updated at : 2026-08-14 21:34:29
- Link: https://puml.online/blog/plantuml-json-diagram-en/
- License: This work is licensed under CC BY-NC-SA 4.0.