VBA JSON - check if a property exist
From Check if property exist · Issue #56 · VBA-tools/VBA-JSON · GitHub Is their any way to check if a property exist? When I try to access a property that is not in a JSON file it throws a 450 error. |
Member
Hi @Martin-Hogge you can use Dim Value As Dictionary
Set Value = JsonConverter.ParseJson("{""a"":[1,2,3],""b"":{""c"":""d""}}")
If Value.Exists("a") Then
For i = 1 to Value("a").Count
' ^ (Collections are 1-based)
Next i
End If
If Not Value.Exists("missing") Then
' Not found
End If Additionally, you can check what keys an object ( Dim Value As Dictionary
Set Value = JsonConverter.ParseJson("{""a"":1,""b"":2,""c"":3})
Dim Key As Variant
' ^ Variant is needed for For Each with strings
For Each Key In Value.Keys
Debug.Print Key
Next Key
' -> a, b, c |
Comments
Post a Comment