Data Structures JSON: How to access of the json data: not directly but by redirection in loop?

0 votes
asked Apr 7, 2020 in Question / help by The-Lu (64,340 points)

For example, if we add a team for each participants ; and a new field color:

!$data={"partlen": "2", "game": "GamePlantuml", "participants": [
{"name": "XYZ" ,"as": "xyz", "team": "A"},
{"name": "RST" ,"as": "rst", "team": "B"},
{"name": "UVW" ,"as": "uvw", "team": "B"}],
"color": {"A": "red", "B": "blue"}
}

How to access to the color of the team, from a participant on a foreach loop?

According to: the last answer and the usage of '%string()'

We test:

  1. :access to json: [$data.color.A, $data.color.B] $part.team -> $data.color.%string($part.team);
  2. :access to json: [$data.color.A, $data.color.B] $part.team -> $data.color[$part.team];
    
  3. :access to json: [$data.color.A, $data.color.B] $part.team -> $data.color.($part.team);
    
  4. :access to json: [$data.color.A, $data.color.B] $part.team -> %get_variable_value($data.color,".",$part.team);
    

But with no success.

  • Is it possible with te current version?
  • or is it on the road map of a new release?

Here is the full code:

@startuml
!$data={"partlen": "2", "game": "GamePlantuml", "participants": [
{"name": "XYZ" ,"as": "xyz", "team": "A"},
{"name": "RST" ,"as": "rst", "team": "B"},
{"name": "UVW" ,"as": "uvw", "team": "B"}],
"color": {"A": "red", "B": "blue"}
}

:a;
!foreach $part in $data.participants
  :$part.name as $part.as;
  :access to json: [$data.color.A, $data.color.B] $part.team -> $data.color of $part.team;
  ':access to json: [$data.color.A, $data.color.B] $part.team -> $data.color.%string($part.team);
  ':access to json: [$data.color.A, $data.color.B] $part.team -> $data.color[$part.team];
  ':access to json: [$data.color.A, $data.color.B] $part.team -> $data.color.($part.team);
  ':access to json: [$data.color.A, $data.color.B] $part.team -> %get_variable_value($data.color,".",$part.team);
!endfor
:b;
@enduml

http://www.plantuml.com/plantuml/uml/hOzFRy8m3CNl-HJ60er9MGyx5cq2BhjE-xyXD9aIMASqGKdA_Y2---A2rB1pJ_7p-yL-7lj0BjIL5ht-aW9TxN0J6rePp04lKGAkgL8iRk9xgyampNtcogBSn8wF_apiq1pHbzSt18daMNp__38U55Ki9xYN2Nft_z2YpeSKdPwYZq_FBLfll_wXSocmiDgwg7SuuQvJIuQcN2zqhN0lzaBaD1AzbNMAYW_eynbG6cZEpzAZ143Us1ad0F9mKEH7R55HAEyXMFZqrkGmEqne8cGJ2QcSpez_EIzSNAScs5LYykYppcPd0nzSQTR3bZZlTiEiTUOTP-yuz62jmlkMN4aBhMAXQpLCFaZCK9vix2cpN5adyiL8Z6DTL_eF

Regard,

1 Answer

0 votes
answered Apr 7, 2020 by plantuml (295,000 points)
selected Apr 20, 2020 by The-Lu
 
Best answer

Thanks for the feedback.

This is fixed in last beta http://beta.plantuml.net/plantuml.jar

@startuml
!$data={"partlen": "2", "game": "GamePlantuml", "participants": [
{"name": "XYZ" ,"as": "xyz", "team": "A"},
{"name": "RST" ,"as": "rst", "team": "B"},
{"name": "UVW" ,"as": "uvw", "team": "B"}],
"color": {"A": "red", "B": "blue"}
}

:a;
!foreach $part in $data.participants
  :$part.name as $part.as;
  :1 access to json: [$data.color.A, $data.color.B] $part.team -> $data.color of $part.team;
  :2 access to json: [$data.color.A, $data.color.B] $part.team -> $data.color[$part.team];
!endfor
:b;
@enduml

http://www.plantuml.com/plantuml/uml/hP3DReCm48JlVehDAaUAr1n1hGANNgl-jn673JWjbR4Zs_IdY7UlbqJ2xJadTcO-LZjUEq_MzvqIYsL3dYu6t0T3IOqPu0eJm5Vg98khyBrMf9bcdxcsRlV1SI7VY07r4NrwVa58aDZ7h-yVnhsaZcM1OnAXDxTtCsgTZz7oBth_y3YZ_SVdFxHA1DP66HlqW0MxLZOCbJnlLIzn5ACG6ULYiJDMKlq6Iwu1hOQfVXgN4W3P5ATy0P23WoANStGELDVIEV06tftHuGaEEwOZqYA1M9RLyM--6Cukun3CBWgdvQkJBT_CIHLwIzs4wYBRvc8TvhvJlm00

There are probably other issues, so do not hesitate to post again !

Thanks

commented Apr 8, 2020 by The-Lu (64,340 points)
...