VBA-JSON Help - If Key doesn't exist

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
using:
GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA

I have a structure like this:
Json("tickets")(i)

Where i is used as the Ticket number

Some tickets but not all have this property:
Json("tickets")(i)("tags")

I tried to loop through it like this but it fails if one doesnt have tags, how can i skip the "tickets" which dont have tags ?


VBA Code:
 If Json("tickets")(i)("tags").Count > 0 Then 'do something'
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The VBA-JSON library constructs a pseudo JSON Object by using dictionaries and collections. With that in mind, if JSON("tickets")(i) is a dictionary object, you can always used the .Exists method to test if tags key is there.

Alternatively, it's less elegant and it is far from good practice, but you could use `On Error Resume Next` to ignore any errors and just soldier on through. But you shouldn't need to if you can just test if the key is there or not with the Dictionary's Exist method.
 
Upvote 0

Forum statistics

Threads
1,224,933
Messages
6,181,843
Members
453,068
Latest member
DCD1872

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top