I have data that I wish to use in two separate diagrams, and thus want to declare it independently of the two diagrams. Within this data, I also have many repeated strings and thus want to use a procedure or function to generate them.
My first approach was to create the JSON structure in a `@startjson/@endjson` block:
@startjson data (id=data)
!procedure $db($obj)
"Store $obj in database"
!endprocedure
{
"name": "Example JSON",
"todo": [
$db("username"),
$db("password")
]
}
@endjson
While this works to define and visualize the JSON data, I can't seem to access the data in another UML (`@startuml/@enduml`) block. Something like `!$myData = %loadJSON(myFile.puml!data)` doesn't work because it's expecting a normal JSON file. Something like `!include myFile.puml!data` just results in a syntax error in the UML block because the JSON is not being declared under a variable name. Adding a variable name to the JSON block above results in a JSON format error.
My second approach was then to define the JSON as a variable in a UML block instead, so that the block could be included by other UML blocks and reference the variable name:
@startuml example
!procedure $db($obj)
"Store $obj in database"
!endprocedure
!$myData = {
"name": "Example JSON",
"todo": [
$db("username"),
$db("password")
]
}
@enduml
This only resulted in a JSON format error whenever the procedure is used. I played with using a function instead, and with the resulting value being quoted or unquoted, but to no avail. I'd guess the format check is occurring before the procedure/function is evaluated (if it's evaluated at all).
Is there anyway to use procedures/functions in a JSON variable declaration to fix this second approach? More generally, is there a way to get the behavior I'm looking for?