Render JSON / YAML as a diagram
Introduction
Raw config and API payloads are tedious to read: a single order JSON expands into a dozen indented lines, and a YAML deployment manifest into dozens of nested ones. Both engines have a way to turn such “pure data” into a structure diagram. PlantUML ships native @startjson / @startyaml directives that render the data as a tree automatically. Mermaid has no built-in JSON parser, but its flowchart syntax maps naturally onto a tree, which makes it more flexible in return. This article draws the same order payload in both engines and explains when each one is the better choice.
PlantUML version
PlantUML has dedicated diagram types for data: wrap JSON in @startjson and YAML in @startyaml, and the result is a tree of field names where indentation maps straight onto nesting depth.
1 | @startjson |
Key points:
No extra declaration needed: paste the payload as-is and every field becomes a node.
Arrays expand into sibling nodes: the two entries of the
itemsarray become parallel branches.YAML works the same way: swap
@startjson/@endjsonfor@startyaml/@endyaml. For example, a Kubernetes deployment manifest:1
2
3
4
5
6
7
8
9
10
11
12
13@startyaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
template:
spec:
containers:
- name: my-app
image: my-app:1.0
@endyamlCareful: do not put JSON inside
@startuml— it will be parsed as ordinary UML text and produce garbage output.
Mermaid version
Mermaid has no JSON directive, but a flowchart’s “nodes plus edges” is a natural fit for a tree. The technique is to treat each object as a node and each field as an edge.
1 | flowchart TD |
Key points:
Quote node labels with square brackets: write
ROOT["ORD-2026-1042"], notROOT[ORD-2026-1042]— unquoted labels containing spaces get truncated.flowchart TDlays out vertically,LRhorizontally; useLRfor large structures to save horizontal space.You decide how to handle arrays: a label like
items (2)summarises the array, and you attach the individual entries below it — Mermaid does not expand arrays on its own, and this “summary plus detail” shape reads more like how people parse data.subgraphgroups one level of the structure:1
2
3
4
5
6
7flowchart TD
subgraph A["customer"]
direction TB
A1["name = Alice"]
A2["tier = gold"]
end
ROOT["ORD-2026-1042"] --> ANever paste a raw JSON string into a label: the quotes and braces inside
{"a": 1}are parsed as Mermaid syntax, so replace them with plain text first.
Side-by-side
| Dimension | PlantUML | Mermaid |
|---|---|---|
| Native data support | @startjson / @startyaml build the tree for you |
None; you hand-write nodes and edges in a flowchart |
| Cost of a data change | Edit the JSON source and the diagram updates itself | Every new field needs another arrow |
| Array handling | Expands automatically into sibling nodes | You decide between a summary node and per-item nodes |
| Control | Structure is fixed, biased toward faithful reproduction | Any layout, any grouping, any annotation |
| Output size | Tiny — a few lines of data produce a whole diagram | Grows noticeably as node count climbs |
Which to pick: to drop a data snapshot into a README or an API doc, use PlantUML’s @startjson — it is the least work. If you want to add grouping, callouts or status markers, or the payload only has three fields, a Mermaid flowchart is clearer. Mixing is fine too: use Mermaid to explain the structure and PlantUML to attach a verbatim snapshot.
Wrap-up
Turning JSON and YAML into diagrams is fundamentally about treating data as structure. PlantUML takes the automatic route — one directive turns the source into a tree. Mermaid takes the manual route and draws the hierarchy explicitly with a flowchart. The first suits snapshots and quick archival; the second suits real documentation where the diagram has to explain and annotate.
- Title: Render JSON / YAML as a diagram
- Author: puml.online
- Created at : 2026-10-23 01:05:00
- Updated at : 2026-10-23 01:06:49
- Link: https://puml.online/blog/json-yaml-as-diagram-en/
- License: This work is licensed under CC BY-NC-SA 4.0.