Getting key/items from JSON data (API connection, VBA)

S_Hamel
S_Hamel used Ask the Experts™
on
Hi there, I am trying to connect to the TSheets(www.tsheets.com) API, and load all the job codes into a table . I can successfully connect and get the JSON, but I currently have to hard code the job code in order to get the info. I am stuck on how to get the codes via the keys/item in the dictionary.  In the example below, '5834988' is the job code, but I have to hard code it in. I just want to pull '5834988' via the dicationary.

Sample JSON:

{
 "results": {
  "jobcodes": {
   "5834988": {
    "id": 5834988,
    "parent_id": 0,
    "assigned_to_all": true,
    "billable": false,
    "active": true,
    "type": "regular",
    "has_children": false,
    "billable_rate": 0,
    "short_code": "",
    "name": "Job 1000"
}
}
}
}

Code:

Set p = JsonConverter.ParseJson(jsonStr)
   
    For Each key In p("results")("jobcodes").Keys
        Debug.Print p("results")("jobcodes")("5834988").item("id")
        Debug.Print p("results")("jobcodes")("5834988").item("parent_id")
        Debug.Print p("results")("jobcodes")("5834988").item("active")
        Debug.Print p("results")("jobcodes")("5834988").item("type")
        Debug.Print p("results")("jobcodes")("5834988").item("name")
 
    Next key
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I figured it out :) The line below will get the me job code I need.

p(Key); Key

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial