-
-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamically create a json structure inside the preprecessor function #328
Comments
Can you please provide an example of your preprocessor function? |
My use case: I'm tracking in a sequence diagrams multiple queues which would greatly benefit from the ability to (a) start with an empty JSON array, and then (b) have the ability to add and remove entries. My queues are:
I'll also comment in the above links |
…json_remove`) From those requests: - https://forum.plantuml.net/15436/allow-update-json-object-or-array-value - https://forum.plantuml.net/17474/modify-json-variables-in-preprocessor - https://forum.plantuml.net/18418/request-%25set_json_keys-function-json-writing-capabilities - plantuml#328 - plantuml#1733
Hello @break2make, @philCryoport, @Potherca, and all, Available from last snapshot (~v1.2024.5beta1), you can now use:
Then:
From: See also: Regards, |
Hi @The-Lum -- Trying this out first with a "Hello World":
It threw the following error:
Line 8 is Note that I tried both I also tried assigning the return of the remove and the add calls to newly declared variables -- identical NPE to the above...except it doesn't call out line 8, nor does it say "Some diagram description contains errors":
I also tried assigning to the same variable -- identical to the second situation, "value is null" NPE, doesn't call out line 8, nor does it say "Some diagram description contains errors":
|
Hi @philCryoport, Thanks a lot for your detailed tests. Currently the @startuml
!$foo = [12, 13]
!$a = [14, "ab"]
!$foo = %json_add($foo, $a)
Alice -> Bob : $a
Alice -> Bob : $foo
@enduml @startuml
!$a = 42
!$foo = { "name": "John", "age" : 30 }
!$foo = %json_remove($foo, name)
!$v = %str2json("[1, 2]")
!$foo = %json_add($foo, "name", $v)
Alice -> Bob : $a
Alice -> Bob : $foo
Alice -> Bob : Do you know **$foo.name** ?
@enduml And there are some side effects on scalar type ( Then I must to do more boundary check on that. Thanks for your tests. |
That fixes: - plantuml#328 (comment) Here is a fix for `int` and `string`, in order to manage: ```puml %json_add({"age" : 30}, name, 123) '=> {"age":30,"name":123} ``` ```puml %json_add({"age" : 30}, name, Sally) '=> {"age":30,"name":"Sally"} ``` [FYI @philCryoport] Reagrds, Th.
Thank you @The-Lum -- lemme know when you have a snapshot build ready and I'll test it on my box:
|
Hello @philCryoport, With the last snapshot of yesterday evening you can now test. Good test... Regards, |
Hi @The-Lum Yep, tried out the basic stuff with
However there's no checking with a
Result - two "name" attributes: I also tried removing an attribute that I had already removed:
Result - No warning thrown...which might be ok...that depends on the standard being followed: The classic sempf joke is running through my head... |
Hi @philCryoport, Good catch! Internally plantuml use the minimal-json; then for:
We will now create the new function And you're right, unit tests look strangely like:
Regards, |
From this request: - plantuml#328 (comment)
Hi all, [This is an Issue Review] 👀
Regards. |
I have an usecase where I want to find the max of an array. If I have a predefined json struct having a {"key": [12, 13, 14]}, then max() function return the max value 14. However, there are few cases, where I have to generate {"key": [12, 13, 14]} dynamically with variable number of elements in list. Please help to generate a dynamic json structure or update an existing jason structure in plantuml preprocessor.
The text was updated successfully, but these errors were encountered: