Data Structures JSON: Return 'false value' when we point to a json field which does not exist

+2 votes
asked Apr 16, 2020 in Wanted features by The-Lu (64,760 points)

First: Thanks for your json developpment.

Could you add this functionality :

  • Return 'false value' (for testing on '!if' function) [or 'undef'] when we point to a json field which does not exist (for a element on the json data) ?

For example : What's happen when a data is missing on a json Data Structures (example, with a 'color' field missing for the 'eve' employee)

Here is an example:

@startuml
!$foo = { "company": "Skynet", "employees" : [
  {"name" : "alice", "salary": 100, "color" : "pink"},
  {"name" : "bob", "salary": 50, "color" : ""},
  {"name" : "carol", "salary": 50, "color": false},
  {"name" : "dave", "salary": 50, "color" : null}
  ',{"name" : "eve", "salary": 50}
]}

start
!foreach $emp in $foo.employees
  !if $emp.color
    #$emp.color:The salary of $emp.name is $emp.salary (color: $emp.color);
  !else
    :The salary of $emp.name is $emp.salary (color: no color);
  !endif
!endfor
@enduml

Link:
http://www.plantuml.com/plantuml/umla/bP11IyD048Nl-ojUre8AeTI3buY_Gc_YOPhEqgMJdR0RXL3otsMJeeb1eQVbiU_x7aonSQfunXcsrgQbqDiAzkNK1-vi2SjDAzep9uiARmOusq0DvsH9VCsvb4WePl1XjokpI3IEZTQ7antA9RRN_G9wN3AhVarHvI-YWYD9_9ivq2V_Cn8-H0O3t9OpXbV8ODu7Or97iJE5qyXK7x7XfeKFo8VRVf_708Ltu-Tsd340SFEJgzSZOt93ByKy3P-cSFcxczepq_rJbhCa7ftNYe9YhWa7xqn-dCOl

In order to test, please to uncomment the line, : ',{"name" : "eve", "salary": 50}

Thanks for your actions,
Regards,
Th.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.
...