Multilingual Wiki Documentation

You are currently using syntax.
In an attempt to improve PlantUML documentation...
Please do not use this website for your own diagrams.
You can click here and use the online server here for your own documentation.

Recent changes    Wiki Toc    View page history    Add new chapter    Reorder page    Raw

Variable definition

In addition to existing type (String and Integer), you can define JSON variable. Example:

!$foo = { "name": "John", "age" : 30 }

Access to data

Once a variable is defined, you can access to its members:

@startuml
!$foo = { "name": "John", "age" : 30 }
Alice -> Bob : Do you know $foo.name ?
@enduml

Complex structures

It is possible to use complex JSON objects and arrays. Definition can be put on several lines :

@startuml
!$foo = { "company": "Skynet", "employees" : [
  {"name" : "alice", "salary": 100 },
  {"name" : "bob", "salary": 50} ]
}
start
:The salary of $foo.employees[0].name is $foo.employees[0].salary;
@enduml

Loading data

Some standard function provides a way to load JSON object from URL or local files:

!$foo = %loadJSON("http://foo.net/users/list.json")
!$foo2 = %loadJSON("myDir/localFile.json")

Loop

If you define array, you are probably expecting loop feature.

@startuml
!$foo = { "company": "Skynet", "employees" : [
  {"name" : "alice", "salary": 100 },
  {"name" : "bob", "salary": 50} ]
}
start
!for $emp in $foo.employees
:The salary of $emp.name is $emp.salary;
!endfor
@enduml

[SW] Some remarks * for or better foreach ? * It would be nice to also have "break" and "continue" * It would be nice to also have the for or while loop with a standard variable

Full Example

[KJW] From a example worked in a forum question

@startuml
!unquoted function DRAW($x) return %set_variable_value($x, 1)

!function addComponent($part, $component, $as)
    !if %variable_exists($part)
        participant "$component" as $as
    !endif
!endfunction

!function addBox2($part, $box, $colour, $data)
    !if %variable_exists($part)
        box "$box" #$colour
            !for $item in $data.participants
                addComponent($part, "$item.name" as $item.as)
            !endfor
        end box
    !endif
!endfunction

DRAW(PART25)

!ifdef PART25
title  TESTING  (Boxes & Participants)  Part25
!endif

!$data={"participants" :[
{"name": "XYZ" ,"as": "xyz"},
{"name": "RST" ,"as": "rst"},
{"name": "UVW" ,"as": "uvw"}
]
}

addBox2("PART25", "New Box", "white" ,"$data")
@enduml


Please report any bugs to plantuml@gmail.com or here.
This website is still in beta testing.