jsonUtils

Utilities for use with jsongo.v2.ahk.

    #Requires AutoHotkey v2.0

; Requires jsongo.v2.ahk

; Returns an array of json objects from a JSON file.
parseJsonArray(filePath)
{
  if !FileExist(filePath)
    throw Error("File not found: " filePath)

  result := []

  jsonText := FileRead(filePath)
  result := jsongo.Parse(jsonText)
  return result
}

; Return an Array containing all the json objects
; that contain myKey.
extractKeyObjs(jsonObjs, myKey, defaultObj := 0)
{
  returnArray := Array()
  For each, jsonObj in jsonObjs
  {
    if jsonObj.Has(myKey)
    {
      returnArray.Push(jsonObj)
      if defaultObj and jsonObj.Has("default")
      {
        defaultObj := jsonObj
      }
    }
  }
  return returnArray
}