Page 1 of 1
Please enhance SetJSONArray() and SetJSONObject()
Posted: Sat Jul 14, 2018 7:55 am
by Little John
PB's other
SetJSON*() commands
assign values to JSON data.
With
SetJSONArray() and
SetJSONObject() this is not possible. They only change the JSON type, so that there is an empty array or empty object, respectively.
Please enhance SetJSONArray() and SetJSONObject() so that they accept an optional parameter that allows to assign an existing array or object, respectively.
Code: Select all
SetJSONArray(JSONValue [, array])
SetJSONObject(JSONValue [, object])
Currently, we have to write our own code in order to achieve this, see
viewtopic.php?f=13&t=71020
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Sat Jul 14, 2018 9:35 pm
by the.weavster
+1
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Sat Jul 14, 2018 10:25 pm
by NicTheQuick
+1
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Sat Jul 14, 2018 11:21 pm
by kenmo
+1
A related request is a function to copy JSON objects/arrays ("copy" or "merge" or "insert" etc.)
I added functions for these requests to my own JSON_Helper.pbi
https://raw.githubusercontent.com/kenmo ... Helper.pbi
Code: Select all
SetJSONObjectEx(*JSONValue, *Object = #Null)
SetJSONArrayEx(*JSONValue, *Array = #Null)
CopyJSONNode(*Src, *Dest, Key.s = "") overwrites *Dest OR adds as a member if a Key is specified
also added: ComposeJSONNode(*Node, IndentSpaces, NewLine) to Compose a subset of a JSON
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Sun Jul 15, 2018 1:53 pm
by Little John
Hi kenmo,
I wasn't aware of your JSON_Helper.pbi. It looks good and useful, thank you!
I see a particular problem, though: Any code that is inside a module currently cannot use code from JSON_Helper.pbi, because that code is not inside of a module. If you'd "wrap" the code in a module, then it could be used even by other code that is also inside of a module. Just a suggestion.
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Sun Jul 15, 2018 7:53 pm
by davido
+1
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Mon Jul 16, 2018 12:08 pm
by RSBasic
+1
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Mon Jul 16, 2018 3:28 pm
by kenmo
I wasn't aware of your JSON_Helper.pbi. It looks good and useful, thank you!
I see a particular problem, though: Any code that is inside a module currently cannot use code from JSON_Helper.pbi, because that code is not inside of a module. If you'd "wrap" the code in a module, then it could be used even by other code that is also inside of a module. Just a suggestion.
I don't think I shared my JSON include on the forum before.
Can a PB Module not call functions from a regular IncludeFile?
I guess I will try that. I don't write PB Modules much, they have some quirks that turned me back to regular IncludeFiles.
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Mon Jul 16, 2018 8:53 pm
by Little John
kenmo wrote:Can a PB Module not call functions from a regular IncludeFile?
No, it can't. There are requests for this feature, but at least currently this is not possible. Code inside a module can only call code which is inside a module, too.
See this example:
Code: Select all
Procedure CantBeCalledFromAModule ()
Debug "Hi there!"
EndProcedure
;----------------------
DeclareModule Test
Declare Demo()
EndDeclareModule
Module Test
Procedure Demo ()
Debug "Hello!"
; CantBeCalledFromAModule ()
EndProcedure
EndModule
;----------------------
CantBeCalledFromAModule()
Test::Demo()
It works fine. After uncommenting line 13, you'll get an error.
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Mon Jul 16, 2018 10:41 pm
by StarBootics
Little John wrote:kenmo wrote:Can a PB Module not call functions from a regular IncludeFile?
No, it can't. There are requests for this feature, but at least currently this is not possible.
It's possible using CallFunctionFast(), in the following code I'm passing the procedure address directly but it's possible to store this address in a global variable inside the module and use it instead.
Code: Select all
Procedure CantBeCalledFromAModule ()
Debug "Hi there!"
EndProcedure
;----------------------
DeclareModule Test
Declare Demo(CanBeCalledFromModule.i)
EndDeclareModule
Module Test
Procedure Demo(CanBeCalledFromModule.i)
Debug "Hello!"
CallFunctionFast(CanBeCalledFromModule)
EndProcedure
EndModule
;----------------------
Test::Demo(@CantBeCalledFromAModule())
Best regards
StarBootics
Re: Please enhance SetJSONArray() and SetJSONObject()
Posted: Tue Jul 17, 2018 6:29 am
by Little John
StarBootics wrote:It's possible using CallFunctionFast()
Yes, that's right.
I was meaning normal, direct calling. And
CallFunctionFast() is fairly limited.
[u]Documentation[/u] wrote:Note: This function is not very flexible and does not handle string/float/double/quad parameters or string/float/double/quad returns.