Page 1 of 1
Pass JSON data to program
Posted: Sat Jun 15, 2024 3:10 pm
by Maz
Hey, I try to pass JSON data as an argument to a program using
RunProgram().
The JSON data for example is
{"date_id":"20240511","date_type":"1"}.
It seems I can not pass the quotes correctly. Based on what is possible in the shell, I would write:
Code: Select all
Arguments$ = ~"api get getHouseholdStoragePsReport '{\"date_id\":\"20240511\",\"date_type\":\"1\"}'"
p = RunProgram(Command$, Arguments$ ; ...
Here however it seems the single quotes gets passed as part of the fourth argument.
Re: Pass JSON data to program
Posted: Sat Jun 15, 2024 4:31 pm
by PBJim
Welcome to the forum. You need to use the UnescapeString() function...
https://www.purebasic.com/documentation ... tring.html
Also add the mode #PB_String_EscapeJSON as the second parameter of the function.
I'm sorry I can't test it and give you an example, because I use PB 6.00 which doesn't include #PB_String_EscapeJSON.
Re: Pass JSON data to program
Posted: Mon Jun 17, 2024 6:12 am
by verifiablefile
Maz wrote: Sat Jun 15, 2024 3:10 pm
Hey, I try to pass JSON data as an argument to a program using
RunProgram().
The JSON data for example is
{"date_id":"20240511","date_type":"1"}.
It seems I can not pass the quotes correctly. Based on what is possible in the shell, I would write:
snow rider
Code: Select all
Arguments$ = ~"api get getHouseholdStoragePsReport '{\"date_id\":\"20240511\",\"date_type\":\"1\"}'"
p = RunProgram(Command$, Arguments$ ; ...
Here however it seems the single quotes gets passed as part of the fourth argument.
Passing JSON data as an argument to a program can be tricky because JSON often includes quotes and special characters that need to be properly escaped. The method for escaping quotes and special characters depends on the shell and programming environment you're using.
Re: Pass JSON data to program
Posted: Wed Jul 02, 2025 8:13 am
by Henjamin
Maz wrote: Sat Jun 15, 2024 3:10 pm
Hey, I try to pass JSON data as an argument to a program using
RunProgram().
The JSON data for example is
{"date_id":"20240511","date_type":"1"}.
It seems I can not pass the quotes correctly. Based on what is possible in the shell, I would write:
Code: Select all
Arguments$ = ~"api get getHouseholdStoragePsReport '{\"date_id\":\"20240511\",\"date_type\":\"1\"}'"
p = RunProgram(Command$, Arguments$ ; ...
drive mad
Here however it seems the single quotes gets passed as part of the fourth argument.
I considered using quotation marks for the entire argument and escaping the inner quotation marks.
Re: Pass JSON data to program
Posted: Wed Jul 02, 2025 9:20 am
by Caronte3D
If you only need to pass an argument, and the Command$ program is yours, you can send the json as base64 then come back to the original json string on the Command$ program.