How to parse json GET request with VBA?

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
I have a json api that I would like to fetch data from, however I can't figure out how to convert the json data into something useful.

VBA Code:
Sub getJSON()
Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String

myurl = "http://localhost:5000/api/v1/battery?limit=1"
xmlhttp.Open "GET", myurl, False
xmlhttp.send

Debug.Print (xmlhttp.responseText)

With Sheets("JSON")
    .Cells(1, 1).Value = xmlhttp.responseText
    .Cells(2, 1).Value = Split(xmlhttp.responseText)
   
End With

End Sub

The json response I have is:

VBA Code:
{"success":true,"count":1,"pagination":{"next":{"page":2,"limit":1}},"data":[{"_id":"5ec3d0c12cf31b3dfc48d540","data":{"alarmType":"Low Battery","devideId":"TEST123","reset":false},"created":"2020-05-19T12:27:45.999Z","__v":0}]}

From jsonplaceholder.

VBA Code:
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}


I would like to get the results in a Table.

Any suggestions?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
I would really like if someone could show me how to access one piece of information in the string.

I have googled and it looks like I should use a dictonary, but I am not sure how to?
 

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,297
Office Version
  1. 2010
Platform
  1. Windows
i can assist with this. what do you want to get
 

Watch MrExcel Video

Forum statistics

Threads
1,129,587
Messages
5,637,232
Members
416,963
Latest member
samfuge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top