Data Structures JSON: How to concatenate values from json table?

0 votes
asked Apr 6, 2020 in Question / help by The-Lu (12,840 points)

This is link to the question: https://forum.plantuml.net/10884/data-structures-json
I test: and that's marvelous! (Thanks a lot)[I posted comment, but that's perhaps better to open a new question here]


And now: 

  • How to concatenate value from json table?

If, for example (from the example of  https://forum.plantuml.net/10884/data-structures-json) 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 :

  1. directly:
     :with direct concat: $data.game + "_" + $part.name;
  2. 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_

1 Answer

0 votes
answered Apr 6, 2020 by plantuml (241,480 points)
selected Apr 7, 2020 by The-Lu
 
Best answer

Many thanks for your tests!

We have fixed several bugs in last beta http://beta.plantuml.net/plantuml.jar (including quote management)

The online server runs now with this beta.

  • By design, you cannot use "direct concat" because the parser is not clever enough. However, using an intermediate var (!$b) is not very user friendly so we have added a new %string() function you can use in that case (see examples)
  • Be carefull : there was an ending semicolon in your $b affectation, and this confuse the parser. Ideally, we should print an error message in that case. Right now, we do not yet :-)
Here are two working examples :
Please go on with your tests !
Thanks again !
...