Im trying to parse data from a Json File using VBA Json which is like this :
{
"a131331": {
"time" : "10:28 a.m.",
"title" : "first"
},
"b319810" : {
"time" : "11:14 a.m.",
"title" : "third"
},
...
}
I want to replace the key a131331 with 1, b319810 with 2 and so on in the first column of a spreadsheet, and place the other corresponding data in the next columns. So my excel sheet would look like:
ID|Time |Title
1 |10.28|first
2 |11.14|third
Im using this code in VBA :
Public Sub ExcelJson()
Dim FSO As New FileSystemObject
Dim JsonTS As TextStream
Set JsonTS = FSO.OpenTextFile("M:\Ds Downloads New\test.json", ForReading)
JsonText = JsonTS.ReadAll
JsonTS.Close
Set JSON = ParseJson(JsonText)
i = 2
For Each Item In JSON
Sheets(1).Cells(i, 1).Value = Item("time")
Sheets(1).Cells(i, 2).Value = Item("title")
i = i + 1
Next
MsgBox ("complete")
End Sub
I understand I can create a column with the number range starting from 1 for the ID column. But how do I parse those objects a131331 and b319810?
iin your cell?Steets(1).Cells(i,1).Value = i - 1for theIDcolumn,Sheets(1).Cells(i, 2).Value = Item("time"), etc.JSON.ParseandJSON.ToArray, then you can process the array or output it to worksheet.