Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
VBA: JSON API -> Excel
Sub js_json_api_example()
Dim req As MSXML2.ServerXMLHTTP60
Dim apiURL, ret As String
Set req = New MSXML2.ServerXMLHTTP60
' Example API:
apiURL = ""
' Verbindung herstellen
req.Open "GET", apiURL, False
' Status in Zelle A1 ausgeben
Range("a1").Value = req.Status & " - " & req.statusText
' JSON unformatiert in A2 ausgeben
ret = req.responseText
Range("a2").Value = ret
' JSON parsen
Dim jsonObject As Object
Set jsonObject = JsonConverter.ParseJson(ret)
' Variable Temp ausgeben (in Celsius umgerechnet, daher -273.15)
Range("a3").Value = Round(jsonObject("main")("temp") - 273.15)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment