VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.74k stars 566 forks source link

Need Help - If Property doesn't exist #240

Closed obie7712 closed 1 year ago

obie7712 commented 1 year ago

Hi, my JSON structure is like this:

Json("tickets")(1) Json("tickets")(2) etc..

Some "Tickets" have: Json("tickets")(1)("tags") but not all

in VBA, how can i ignore the "tickets" that don't have tag ?

I tried this but it errors with object required Json.Exists("tickets")(1)("tags")

Nick-vanGemeren commented 1 year ago

Don't use complex one-liners.

Try something like:

    Dim ticket As Dictionary
    For Each ticket In Json("tickets")
        If ticket.Exists("tags") Then ProcessTags ticket("tags")
      Next

Remember to make a reference to Microsoft Scripting Runtime.

If that solves your problem, please close the issue. If not, explain further and maybe attach a file of JSON input.

obie7712 commented 1 year ago

For Each ticket In Json("tickets") If ticket.Exists("tags") Then ProcessTags ticket("tags") Next

Thank you, that has worked :)