loadJSON function

+4 votes
asked May 2, 2020 in Wanted features by Seb
Hi,

When do you plan to integrate loadJSON function as it is proposed in the wiki ?

http://wiki.plantuml.net/site/preprocessing-json

Thanks

1 Answer

+1 vote
answered Nov 10, 2021 by Aljoscha Rittner

Good morning!

I implemented a loadJSON function yesterday and wanted to make a pull request shortly. The implementation uses SFile and SURL so that JSON data can be loaded locally and from REST interfaces. I followed the proposal on the http://wiki.plantuml.net/site/preprocessing-json site. However, there are two more optional parameters. A default JSON if the data source does not provide any data and the possibility to define a charset encoding.

Here is an example:

@startuml

' This example works only with the latest plantuml snapshot an implemented
' %loadJSON function

' Default JSON, if we don't get a content from the data source
!$DEF={"status": "not connected"}

' Load from Spring boot service with actuator 'health' endpoint
!$TEST=%loadJSON("http://localhost:7778/management/health", $DEF)

' Load from local file (relative located in plantuml.include.path list)
!$DEMO=%loadJSON("demo.json")

title Load JSON example with $DEMO.status

' Simple usage
[Service] -> ($TEST.status): is

' Embedded rendering of JSON structure
 rectangle Inner #tan as "
    {{json
    $TEST
    }}
    Health of management service at %date()
    "

@enduml


commented Nov 10, 2021 by plantuml (295,000 points)
That's great!

We are looking forward to reviewing your pull request and we will merge it if there is no security issue there.

Thanks!
commented Nov 10, 2021 by Aljoscha Rittner
Hi!

I created a PR: https://github.com/plantuml/plantuml/pull/755

Any comments and ideas to improve it are very welcome. :-)

best regards, Aljoscha
...