Sub Class_Globals
Private jsonM As Map
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(jsonString As String)
Dim jsonP As JSONParser
jsonP.Initialize(jsonString)
jsonM = jsonP.NextObject
End Sub
public Sub Query(path As String, default As Object) As Object
Dim ret As Object = InnerQuery(jsonM, path)
If ret = Null Then
ret = default
End If
Return ret
End Sub
private Sub InnerQuery(obj As Object, path As String) As Object
Dim keys() = Regex.Split("/", path) As String : path = ""
If keys.Length = 0 Then Return obj
Dim key As String
For i = 0 To (keys.Length - 1)
key = keys(i) : If key <> "" Then Exit
Next
If key.Length = 0 Then Return obj
For j = i + 1 To (keys.Length - 1)
path = path & keys(j) & "/"
Next
If obj Is Map Then
Dim map = obj As Map
obj = InnerQuery(map.GetDefault(key, Null), path)
Else If obj Is List Then
Dim lst = obj As List
Try
obj = InnerQuery(lst.Get(key), path)
Catch
obj = Null
End Try
End If
Return obj
End Sub