Data Structures JSON

0 votes
asked Feb 27, 2020 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, 2020 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, 2020 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, 2020 by plantuml (278,240 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, 2020 by kjw
Juts tried that and I get a 500 Error on the web interface and planttext

1 Answer

0 votes
answered Feb 27, 2020 by plantuml (278,240 points)
commented Apr 6, 2020 by The-Lu (48,920 points)

Feedback still welcome :-)

I test: and that's marvelous! (Thanks a lot)


And now: 

  • How to concatene value from json table?

If, for example, I add a field 'game' : 

!$data={"partlen": "2", "game": "GamePlantuml", "participants" :[
  • How to refer to '$data.game' on the 'for loop'?

We test on two differents ways :

  • directly:
 :with direct concat: $data.game + "_" + $part.name;
  • with usage of an intermediate variable ($b).
  !$b=$data.game + "_" + $part.name;
  :with var b: $b;

And on the two way, the result is not done:

  1. on the first, we observe : 'GamePlantuml + "_" + XYZ' 
    --> Why the concatenation is not done ?
  2. on the second : '"GamePlantuml"_0'
    --> Why we observe '0' and not 'XYZ'? + management of quote (") on var ?

Here is the example used:

@startuml
!$partlen=2
!$data={"partlen": "2", "game": "GamePlantuml", "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;
  :with direct concat: $data.game + "_" + $part.name;
  !$b=$data.game + "_" + $part.name;
  :with var b: $b;
!endfor
:b;
@enduml
http://www.plantuml.com/plantuml/uml/VL39QiCm4BtFLqm6tsf2oL76a5klfVj2AUEbYS1HWgGaROF_lJE9Yj9BB_AyvJqUdeV8FcvN0qoAZLn3x-gPt1r7hW-KA398CogH5hpg5Lp9ztfWfqdbrMTRkn4c49fNE91BrgVd5yAIE2Zu_FgciJnJRsxlikf3_AlUFpncTRlRqmXlC9vDFUwS9YIyhIy14S4mLc0AgqzIAvXyh7tFxHAF55g7EVux7X1FYQbkG0vuGXmgbVOsBh6plcyZjclNSZIfPA7s2wHtaZStQ6fIDFM_fbozOu-DL3QojdUT30OZzrnk-TC_
commented Nov 16, 2020 by The-Lu (48,920 points)

Hello Martin,

Thank you for this supplement. I did open a specific case to my remark, but hadn't updated my remark here. This is now done ...

See this Q&A:

Regards,
Th.

...