Data Structures JSON

0 votes
asked Feb 27 in Question / help by kjw

Using JSON data structures seem to be possible in  basic way :

@startuml

!$partlen=2

!$data={"partlen": "2", "participants" :[

{"name": "XYZ" ,"as": "xyz"},

{"name": "RST" ,"as": "rst"},

{"name": "UVW" ,"as": "uvw"}

]

}

'!$partlen=$data.partlen

!$i=0

   

:a;

:$i;

:$partlen;

':$data.participants[$i].name as $data.participants[$i].as;

:$data.participants[0].name as $data.participants[0].as;

:$data.participants[1].name as $data.participants[1].as;

:$data.participants[2].name as $data.participants[2].as;

:b;

@enduml

but using parameters to access the content produces errors, using integers is ok.

Its this a bug or a missing enhancement

commented Feb 27 by kjw

It would be great to get it working with a loop :

@startuml

!$partlen=2

!$data={"participants" :[

{"name": "XYZ" ,"as": "xyz"},

{"name": "RST" ,"as": "rst"},

{"name": "UVW" ,"as": "uvw"}

]

}

!$i=0

:A;

!while $1<=$partlen

:data.participants[$i]name as $data.participants[$i].as;

!$i = $i + 1

!endwhile

:B           

!$j=0

:a;

:$j;

':$data.participants[$j].name as $data.participants[$j].as;

:$data.participants[0].name as $data.participants[0].as;

:$data.participants[1].name as $data.participants[1].as;

:$data.participants[2].name as $data.participants[2].as;

:b;

@enduml

commented Feb 27 by kjw

Oddly the foreach loop doesn't cause a syntax error as the while loop above does :

(Not sure it being invoked)

@startuml

!$partlen=2

!$data={"participants" :[

{"name": "XYZ" ,"as": "xyz"},

{"name": "RST" ,"as": "rst"},

{"name": "UVW" ,"as": "uvw"}

]

}

!$i=0

:A;

!foreach $item in $data.participants

:$item.name as $item.as; 

:$i;

        !$i = $i +1

!endfor 

:B;           

!$j=0

:a;

:$j;

':$data.participants[$j].name as $data.participants[$j].as;

:$data.participants[0].name as $data.participants[0].as;

:$data.participants[1].name as $data.participants[1].as;

:$data.participants[2].name as $data.participants[2].as;

:b;

@enduml

But changing to !endforeach does break it but no syntax error 

http://www.plantuml.com/plantuml/png/VOxBJiCm44NNcQ-OZYAneAgIB6r5Adm2RwYw61eZ72McYXqULFbtx52KYZRnQiP7P-vTMiUDQ-iAPl7MJvKoUURdWXtdEmfVUgEtR9mb52k8TcIuLYIG7XwV2EV4DYoVNz_KpG_nrVNDW1lh_k7Rk_i1j-yVr46qXWvyjiuJ41VIZozlZUBDAyRQgHgrmRxNuh0LHX29dY_2QMIBlnjRYJsIWFldJsFkCPwdC5Ec-3iF82ub3WyWr2X33POWubB2cJYENiNbUWWzYKCBEAKcasOoBgQJOZekPfDYjXUV9IoLATgw-W40

commented Feb 27 by plantuml (215,660 points)

With last beta http://beta.plantuml.net/plantuml.jar

You can have

@startuml
!$partlen=2
!$data={"partlen": "2", "participants" :[
{"name": "XYZ" ,"as": "xyz"},
{"name": "RST" ,"as": "rst"},
{"name": "UVW" ,"as": "uvw"}
]
}
!$partlen=$data.partlen
!$i=0
   
:a;
:$i;
:$partlen;
!foreach $part in $data.participants
:$part.name as $part.as;
!endfor
:b;
@enduml

This has not been widely tested, so any feeback is welcome :-)

commented Feb 27 by kjw
Juts tried that and I get a 500 Error on the web interface and planttext

1 Answer

0 votes
answered Feb 27 by plantuml (215,660 points)
...