How to mix JSON objects into a components diagram

0 votes
asked Jan 25, 2021 in Wanted features by Kai
In some cases json objects may be useful to detail certain other objects e.g. components for their attributes and description.

1 Answer

0 votes
answered Jan 25, 2021 by The-Lu (64,340 points)

Hello K.,

You can put JSON data on components, with JSON sub-diagram or embedded diagram, see wanted feature here:

Here is another example:

@startuml
component c1 [
component c1
{{json
{
"name": "component c1",
"color": ["normal", "green", "red"],
"visible": true
}
}}
]

file f1 [
file f1
{{json
{"name": "file f1",
"color": "normal"}
}}
]

c1 -> f1
@enduml


[See on PlantUML online server]

If that can help,
Regards,
Th.

commented Jan 26, 2021 by Martin (8,360 points)

For fun, here's an extended example where the same JSON data is used for both displaying the JSON and for constructing some elements of the diagram:

@startuml
!$data={"participants":[
{"shape": "cloud", "name": "id1", "colour": "#green", "desc": "some text"},
{"shape": "folder", "name": "id2", "colour": "#blue", "desc": "more text"},
{"shape": "database", "name": "id3", "colour": "#red", "desc": "even more text"}
]}

rectangle Outer {
rectangle Inner as "
{{json
$data
}}
"

together {
!foreach $part in $data.participants
$part.shape $part.colour $part.name as "$part.desc"
Inner --> $part.name
!endfor
}

}
@enduml

...