How to display JSON using data loaded with %load_json()?

0 votes
asked Aug 16 in Question / help by dragondive (1,360 points)

Please see the example titled "Complex example" from the docs: https://plantuml.com/json#9b905dab753004a4

Rather than "hardcoding" the JSON data into the puml file, I'd like to load it from a separate JSON file using %load_json() into a variable. Then display that JSON data exactly like the example shows.

However, I couldn't figure out the correct syntax for doing this. The closest I could get was:

@startuml
!$data = %load_json('external_data.json')
json "some title" as Data $data
@enduml

While this does display the JSON data, it looks less elegant and useful than in case of the "hardcoded" data.

JSON display data

Any ideas on how I can do this?

2 Answers

0 votes
answered Aug 20 by chris (2,780 points)
edited Aug 24 by chris

Try using the json diagram type:

Example showing json diagram type

With json as a object/map:

With subdiagram:

commented Aug 24 by dragondive (1,360 points)
I'm using @startuml and @enduml because of allowmixing. I want to include some other diagrams types in the same diagram.
commented Aug 24 by chris (2,780 points)
edited Aug 24 by chris
Updated my answer. The “Complex example: with all JSON basic element” example displays json like a map, so it will look different, depending on your json structure. It’s also possible to embed sub diagrams using a syntax like {{}} so I've added that example too, I think that's what you want
0 votes
answered Nov 19 by Tony Daly (140 points)
Use the following syntaxt

@startjson

!$remote_json = %load_json("external_file.json")

$remote_json

@endjson
...