I'm looking for an idea to help me extract the data from one cell("data"). When the value from another cell ("id") is for example 11, I want to display the corresponding parsed value from "data" into rows and columns from another Excel-Worksheet.I'm using the library (VBA-JSON v2.3.1 JsonConverter)
I have the following JSON-Object:
{
"Messages":[
{
"internalDeviceId":11,
"rawJson":"{\"temperature\":22.6,\"humidity\":37,\"light\":1,\"motion\":1,\"co2\":640,\"vdd\":3.647}"
},
{
"internalDeviceId":12,
"rawJson":"{\"humidity\":30,\"pressure\":1000,\"CO2\":700,\"vdd\":3.654}"
},
{
"internalDeviceId":13,
"rawJson":"{\"latitude\":47.654,\"longitude\":9.654,\"vdd\":3.432}"
},
{
"internalDeviceId":11,
"rawJson":"{\"temperature\":23.0,\"humidity\":38,\"light\":20,\"motion\":0,\"co2\":665,\"vdd\":3.621}"
},
{
"internalDeviceId":11,
"rawJson":"{\"temperature\":22.1,\"humidity\":35,\"light\":15,\"motion\":1,\"co2\":650,\"vdd\":3.425}"
}
]
}
I got the data from a rest API with a VBA code and that is working. At the moment I get the following information in excel:
My code looks like this:
Dim response2 As String
Dim json1 As Object
Dim ws2 As Worksheet
strUrl = "https://xxxxxxxxxxxx/devices/11/"
Set hReq = CreateObject("MSXML2.XMLHTTP")
With hReq
Set ws2 = Worksheets(3)
.Open "GET", strUrl, False
.SetRequestHeader "Authorization", "Bearer " & apitoken
.Send
response2 = hReq.responseText
Set json1 = JsonConverter.ParseJson(response2)
k = 2
For Each item In json1("Messages")
ws2.Cells(k, 3) = item("externalDeviceId")
ws2.Cells(k, 8) = item("rawJson")
k = k + 1
Next item
End With
I just want to split the information from "data" in rows and columns based on a certain "id" for example in this case 11. The structure from "data" depends on "id". I want to do this in VBA without PowerQuery. I was searching for hours and didn't find a solution.
I know that the item I am returning is, itself, a JSON string. To split the information from it, I create another JSON object. I don't know how I can get the information from data into rows and columns because of the different structures of "data".
How can I access these different values depending on the "id"?

