Tuesday, June 18, 2024

Excel VBA - Decoding API responses as JSON

 A blog after 12 years.... I was back to coding and creating utilities for solving operational problems

We decided to have an automated report based on TestCases in TestRails. I decided to use the TestRails API(https://support.testrail.com/hc/en-us/articles/7077083596436-Introduction-to-the-TestRail-API) for pulling information around TestCases in Excel and then massage those numbers for creating an automated report to understand automation progress.

It is kind of tricky in Excel + Mac while writing macros for reading JSON, as the options available are very low. Here are the steps I followed -

1. Download the VBA-JSON file(https://github.com/VBA-tools/VBA-JSON) and run Jsonconverter.bas file

2. Download the VBA-Dictionary file(https://github.com/VBA-tools/VBA-Dictionary) and import Dictionary.cls file

Now you can create objects from the string response. 

sResult = <String response from TestRail API>

Set jsonObject = ParseJson(sResult)

For each dictCase in jsonObject("cases")

    ' strID = dictCase("id")

Next


This helps in navigating through the response from API.