JSON parsing sample import

Discuss RoboTask here
Post Reply
DK.Ideagen
Posts: 22
Joined: Wed Mar 09, 2022 10:33 pm

JSON parsing sample import

Post by DK.Ideagen »

I have found examples of JSON parsing on this forum e.g.

viewtopic.php?p=5646&hilit=json#p5646

However the samples provided do not import as valid.

Running 9.1.1
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: JSON parsing sample import

Post by Oleg »

However the samples provided do not import as valid.
Hm-m-m... I tried to import this task without problem in RoboTask 9.1
You can copy the text of the task and paste it into task list of RoboTask
Oleg Yershov
Oleg
Site Admin
Posts: 3000
Joined: Thu Jan 01, 1970 1:00 am
Contact:

Re: JSON parsing sample import

Post by Oleg »

Also look at the example how you can to do this without JS script

Code: Select all

;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
 
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|0
CatID=INTEGER|444033236
Comment=STRINGLIST
ContinueOnError=INTEGER|0
DisableOnError=INTEGER|0
DoNotStopWhenShutdown=INTEGER|0
ExternalName=STRING|"Task1463"
Hide=INTEGER|0
ID=INTEGER|-1430236606
LogOnAsUser=INTEGER|1
Name=STRING|"JSON parse (without JS script)"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|3
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0

[Actions]
Action1=FOLDER
Action10=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER

[Actions\Action1]
ActionID=STRING|"A_DIALOG_INPUTBOX"
Enabled=INTEGER|-1
Name=STRING|"Input Box"
Params=FOLDER

[Actions\Action1\Params]
default=STRING|"none"
password=STRING|"0"
prompt=STRING|"Input the name"
variable=STRING|"NAME"

[Actions\Action10]
ActionID=STRING|"A_FILE_DELETE"
Enabled=INTEGER|-1
Name=STRING|"Delete File"
Params=FOLDER

[Actions\Action10\Params]
Count=STRING|"1"
deletedirs=STRING|"0"
file0=STRING|"{TempDir}\gendersize.dat"
hidden=STRING|"1"
subdir=STRING|"0"
system=STRING|"1"
ToRecycleBin=STRING|"0"

[Actions\Action2]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER

[Actions\Action2\Params]
case=STRING|"0"
operator=STRING|"0"
type=STRING|"0"
value1=STRING|"{name}"
value2=STRING|"none"

[Actions\Action3]
ActionID=STRING|"A_FLOW_EXIT"
Enabled=INTEGER|-1
Name=STRING|"Exit"

[Actions\Action4]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"

[Actions\Action5]
ActionID=STRING|"A_INET_DOWNLOAD"
Enabled=INTEGER|-1
Name=STRING|"Download files and save in ""{TEMPDIR}"""
Params=FOLDER

[Actions\Action5\Params]
action=STRING|"1"
file0=STRING|"https://api.genderize.io/?name={name}"
filecount=STRING|"1"
proxykind=STRING|"0"
saveas=STRING|"1"
saveasname=STRING|"gendersize.dat"
savedir=STRING|"{TEMPDIR}"
useproxy=STRING|"0"

[Actions\Action6]
ActionID=STRING|"A_GENERAL_RUN_PROG"
Enabled=INTEGER|0
Name=STRING|"Run ""notepad.exe ""{TempDir}\gendersize.dat"""""
Params=FOLDER

[Actions\Action6\Params]
ifnonzero=STRING|"0"
params=STRING|"""{TempDir}\gendersize.dat"""
program=STRING|"notepad.exe"
runas=STRING|"0"
wait=STRING|"2"

[Actions\Action7]
ActionID=STRING|"A_SCRIPT_JSSCRIPT"
Enabled=INTEGER|0
Name=STRING|"JS script"
Params=FOLDER

[Actions\Action7\Params]
expandvars=STRING|"0"
line00000000=STRING|"s = RoboTaskApp().expandtext(""{TextFile({TempDir}\\gendersize.dat)}"");"
line00000002=STRING|"//LogMessage(s);"
line00000004=STRING|"obj = JSON.parse(s);"
line00000006=STRING|"//LogMessage(obj.name + ""|"" + obj.gender);"
line00000008=STRING|"if (obj.gender == null)"
line00000009=STRING|"  {RoboTaskApp().SetUserVariable(""gender"", ""UNKNOWN"");"
line0000000A=STRING|"  }"
line0000000B=STRING|"  else"
line0000000C=STRING|"  {RoboTaskApp().SetUserVariable(""gender"", obj.gender);"
line0000000D=STRING|"  }"
linecount=STRING|"16"
savescript=STRING|"0"

[Actions\Action8]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""text"" with value ""{TextFile({TempDir}\gendersize.dat)}"""
Params=FOLDER

[Actions\Action8\Params]
expand=STRING|"1"
varname=STRING|"text"
varvalue=STRING|"{TextFile({TempDir}\gendersize.dat)}"

[Actions\Action9]
ActionID=STRING|"A_DIALOG_MESSAGE"
Enabled=INTEGER|-1
Name=STRING|"Show ""full json: {text}"""
Params=FOLDER

[Actions\Action9\Params]
icon=STRING|"1"
msg0=STRING|"full json: {text}"
msg1=STRING|"Name: {json:text.name}"
msg2=STRING|"Gender: {json:text.gender}"
msg3=STRING|"Probability: {json:text.probability}"
msg4=STRING|"Count: {json:text.count}"
msgcount=STRING|"5"
playsound=STRING|"0"
showmessage=STRING|"1"

Oleg Yershov
DK.Ideagen
Posts: 22
Joined: Wed Mar 09, 2022 10:33 pm

Re: JSON parsing sample import

Post by DK.Ideagen »

perfect, thanks
Post Reply