In my project, I'm creating a JSON file with VBA code. I want to create a nested JSON file to use my Excel cell's value. To do this I wrote the following code but it's not creating a nested JSON file and I don't know how to do it.
Dim excelRange As Range
Dim jsonItems As New Collection
Dim jsonDictionary As New Dictionary
Dim jsonFileObject As New Scripting.FileSystemObject
Dim jsonFileExport As TextStream
Dim a As Long
Dim cell As Variant
Set excelRange = Cells(2, 1).CurrentRegion
For a = 2 To excelRange.Rows.Count
jsonDictionary("refType") = Cells(a, 6)
jsonDictionary("reference") = Cells(a, 1)
jsonDictionary("engType") = "A5"
jsonDictionary("DMC") = Cells(a, 16)
jsonDictionary ("subTasks")
jsonItems.Add jsonDictionary
Set jsonDictionary = Nothing
Next a
Set jsonFileExport = jsonFileObject.CreateTextFile("C:\Users\ftk1187\Desktop\jsonExample.json", True)
jsonFileExport.WriteLine (JsonConverter.ConvertToJson(jsonItems, Whitespace:=3))
I want to create a nested JSON under the subTasks section. I want to do something like this.

After a lot of tries and Koen's helps, I solve the problem. Final form of codes like this
Dim excelRange As Range
Dim jsonItems As New Collection
Dim jsonDictionary As New Dictionary
Dim jsonDictionary2 As New Dictionary
Dim jsonFileObject As New Scripting.FileSystemObject
Dim jsonFileExport As TextStream
Dim a As Long
Dim cell As Variant
Dim wrdArray() As String
Set excelRange = Cells(2, 1).CurrentRegion
k = 0
For a = 2 To excelRange.Rows.Count
Set jsonDictionary = New Dictionary
jsonDictionary("refType") = Cells(a, 6)
jsonDictionary("reference") = Cells(a, 1)
jsonDictionary("engType") = "A5"
jsonDictionary("DMC") = Cells(a, 16)
wrdArray() = Split(Cells(a, 17), ";")
Set jsonDictionary2 = New Dictionary
For c = 0 To UBound(wrdArray) - 1
jsonDictionary2("SUBTASK" & c) = subs(c + k)
Next c
k = k + UBound(wrdArray)
jsonDictionary.Add "subTasks", jsonDictionary2
jsonItems.Add jsonDictionary
'Set jsonDictionary = Nothing
'Set jsonDictionary2 = Nothing
Next a
Set jsonFileExport = jsonFileObject.CreateTextFile("C:\Users\ftk1187\Desktop\jsonExample.json", True)
jsonFileExport.WriteLine (JsonConverter.ConvertToJson(jsonItems, Whitespace:=3))
