Parse a large Json file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Loop
Posts: 160
Joined: 07 Jan 2019, 14:51

Parse a large Json file

Post by Loop » 01 Jun 2023, 17:07

Hi,
I have a very large json file that I would like to parse. I use the JSON2AHK function from @teadrinker for this. How can I execute the function recursively so that I get all the values and keywords with a loop or function?

So far I have done it this way, but it takes a long time.
AhkObj.contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents[2].itemSectionRenderer.contents[1].videoRenderer.videoId



Code: Select all

JSON2AHK(JSON, Recursive := False) {
   Local
   Static Doc := ComObjCreate("htmlfile")
        , __  := Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
        , JS  := Doc.parentWindow
   If (!Recursive)
      Obj := JSON2AHK(JS.eval("(" . JSON . ")"), True)
   Else If !IsObject(JSON)
      Obj := JSON
   Else If (JSON.toString() != "[object Object]") {
      Obj := []
      Loop % JSON.length
         Obj.Push(JSON2AHK(JSON[A_Index - 1], True) )
   }
   Else {
      Obj := {}
      Keys := JS.Object.keys(JSON)
      Loop % Keys.length {
         K := Keys[A_Index - 1]
         Obj[K] := JSON2AHK(JSON[K], True)
      }
   }
   Return Obj
}

Thanks

Return to “Ask for Help (v1)”