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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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