Maybe this should be the embellished version?
A lot faster.... I adjusted my script for array rather than list; eliminated the map lookup; modified the Boxtext to not display each node;only wrote out the node and value... tested on first 10,000 nodes. There is one test line where I thought the ObjectType for the jsKeyPaths would return ARRAY, but might be using the function wrong.
[EDIT]: my bad, use VarType() not ObjectTypeGet()... the use of "Object" in the Extender docs confused me.
Anyway, this is an excellent Extender and folks.... Json ain't going away
;Winbatch 2021C - Census Data - tests large json return
;uses WinHttp.WinHttpRequest.5.1 for JSON return
;Stan Littlefield, September 14, 2021
;Updated: September 18, 2021 - based on new Extender using array rather than delimited list
;======================================================================================================
IntControl(73,1,0,0,0)
Gosub udfs
AddExtender('ilcjs44i.dll', 0, 'ilcjs64i.dll')
cUrl = "https://api.census.gov/data/2019/acs/acs1/variables.json"
BoxOpen("Parsing:":cUrl,"Please Wait...")
cFile = Dirscript():"CensusAPI.txt"
cJson = Dirscript():"CensusAPI.json"
If FileExist(cFile) Then FileDelete(cFile)
If FileExist(cJson) Then FileDelete(cJson)
request = Createobject("WinHttp.WinHttpRequest.5.1")
request.Open("GET", cUrl, @False )
request.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
request.SetRequestHeader("Accept", "application/json")
request.Send()
jdata = request.ResponseText
request = 0
;persist .json file
;FilePut(cJson,jdata) ;uncomment if needed
;=================================
If jsValid(jdata)
;jstypes = crtypes() ;no need for map, not persisting node types
Object = jsParse(jdata)
BoxTitle("Creating text Output ":cFile )
crTree()
jsObjClose()
BoxShut()
Message("Json Tree Created",cFile)
Else
jsObjClose()
BoxShut()
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()
Fx = FileOpen(cFile,"Write")
output = "node":@tab:"value"
FileWrite(Fx,output)
tree =jsKeyPaths(Object,"")
;just for test
Message("Object Type for tree",ObjectTypeGet(tree)) ;would not expect blank return
Cnt = Arrinfo(tree,1)
i=1
ForEach item in tree
iVal = jsValueGet(Object,item)
If jsValueType(Object,item) <> @JsonObj
output = item:@tab:iVal
If (i mod 100 == 0) Then BoxText("Processing ":i:" of ":Cnt)
FileWrite(Fx,output)
i +=1
If i>10000 Then Break
Endif
Next
FileClose(Fx)
Drop(Fx)
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