Attached a sample Json text [
just rename extension to .json for script]. Basically set up UDf and type map so the script creates a documenter of sorts. Same problem with Json, dates are cast as strings but was thinking of adding a UDF to determine if a Json string could be interpreted as a date. Also, when the text file is written you will see something like
[items][0] OBJECT *obj17424*
Is there anything of significance to the OBJECT value [same seems to apply to ARRAY]?
Finally, since the .json is an array is there a WB like
foreach Date in Items
process
Next
;Winbatch 2021C - Test of new Json Extender
;uses json text file
;Stan Littlefield, September 12, 2021
;======================================================================================================
IntControl(73,1,0,0,0)
Gosub udfs
AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
cJson = Dirscript():"dow.json"
If !FileExist(cJson) Then Terminate(@TRUE,"Cannot Continue... missing file",cJson)
BoxOpen("Parsing:":cJson,"Please Wait...")
cFile = Dirscript():"parsed_dow.txt"
If FileExist(cFile) Then FileDelete(cFile)
jdata = FileGet(cJson)
If jsValid(jdata)
jstypes = crtypes()
Object = jsParse(jdata)
crTree()
jsObjClose()
Message("Json Tree Created",cFile)
Else
jsObjClose()
Message(cJson,"Not Valid Json")
Endif
Exit
:WBERRORHANDLER
geterror()
Terminate(@TRUE,"Error Encountered",errmsg)
Exit
:udfs
#DefineSubRoutine geterror()
wberroradditionalinfo = wberrorarray[6]
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
Return(errmsg)
#EndSubRoutine
#DefineSubRoutine crTree()
output = "node":@tab:"type":@tab:"value":@CRLF
tree =jsKeyPaths(Object,"")
Cnt = ItemCount(tree, @tab)
;Message("",Cnt)
For i = 1 to Cnt
iVal = "" ;default
item = ItemExtract(i,tree, @tab)
iType = jsValueType(Object,item)
iVal = jsValueGet(Object,item)
output := item:@tab:MapKeyFind(jstypes,iType,'NULL'):@tab:iVal:@CRLF
Next
FilePut(cFile,output)
Return(1)
#EndSubRoutine
#DefineSubRoutine crtypes()
maps = $"1,NULL
2,BOOL
4,NUMBER
8,STRING
16,ARRAY
32,OBJECT
$"
jstypes = MapCreate(maps,',',@lf)
Return(jstypes)
#EndSubRoutine
Return