excel data to json converter using vba

Viewed 70
  1. I have a sample input which looks like this: sample input
  2. I need a function which could convert excel table into a json with the following expected output.Excepted output

Few checks to be considered:

  1. Anything after field name, if data is filled for those it should be considered else dont need to include in json as shown in sample output json
  2. Anything in mandatory column, if no data is filled just add them as an empty dictionary as shown in sample output.

Please help me out to get started. Not getting on how to approach this with nested dictionary concept.

code:
Sub jsonConverter()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Tests")
    
    Dim mainheading As Range, itm As Range
    Set mainheading = ws.UsedRange.Columns(1)
    Set itm = mainheading.Cells(1)
    While Len(itm.Value2) > 0
        Debug.Print itm & " : " & itm.MergeArea.Address(0, 0)
        Set itm = itm.MergeArea.Offset(1)
    Wend
End Sub

Loop through sheet 1 and got all the col A values from the merged cells. Need to create a nested dictionary with this.

sample data link: https://docs.google.com/spreadsheets/d/1oV2p7k_1vWsF6jfOYj9LfvC-NELqMLRk/edit?usp=sharing&ouid=108827571916573584534&rtpof=true&sd=true

0 Answers
Related