Is it possible to include JSON as an external source

0 votes
asked Aug 23, 2022 in Question / help by Tony Daly

Including JSON data in a use case diagram as a basic element works fine, However I would like to include the data by referencing an external file rather than embedding the code. I want to do this to have a single source of the JSON (in git).

I imagine it would look something like:

json JSON {link to external file[url/externalfile.json]}

Please ignore my use of incorrect parenthesis. url syntax etc.

Is this possible now using include files, or could this be developed?

1 Answer

0 votes
answered Aug 26, 2022 by plantuml (295,000 points)
The preprocessor has now a %load_json() function that you might find useful. See http://www.forum.plantuml.net/11406/loadjson-function and https://plantuml.com/en/preprocessing#291cabbe982ff775

Note that we are currently renaming %loadJSON() to %load_json() so you may have to try both syntaxes depending on your PlantUML version.

Does it help?
commented Aug 26, 2022 by Tony Daly
Thanks for the response.

Yes %load_json is perfect.I can get it to work showing the json data structure using:

!$remote_json = %load_json("https://gitlab.com/......../example.json")

label l [
=Title:
{{json
$remote_json
}}
]

But I would also like to display it as tabular json as in the examples at the bottom of this page https://plantuml.com/json

json JSON {
   "fruit":"Apple",
   "size":"Large",
   "color": ["Red", "Green"]
}

I tried using the syntax

json TITLE $remote_json

But I get a syntax error. I know that the json is valid.

Any ideas on how to show the basic tabular json with %load_json?
commented Aug 26, 2022 by plantuml (295,000 points)

Thanks for the report.

This has been fixed in last snapshot and on the online server.

Tell us if you find other issues!

commented Aug 26, 2022 by Tony Daly
Many thanks for the prompt solution. Just one more thing: json data loaded using %load_json doesn't work if the root is an array rather than an object.

Being able to show json data graphically from a version controlled solution such as a remote git repo, is fantastic for maintaining documentation.
...