I have for a long time used QHarr's excellent answer to parse JSON by using a JSON parser.
Code used is: Set Json = JsonConverter.ParseJson(.responseText)
It have stopped working and it doesn't work for the following URL request URL = "https://api.gleif.org/api/v1/lei-records?filter[lei]=5493001ZDI5KQPZTPI85"
, so I have tried to use another method.
I'm trying to retrieve the legal name as an exampel:
It seems like I get a JSON object in return but I'm struggle with how I can print the values to the excel sheet. I thought this method would do the trick as suggested by July Tech:
ws.Cells(1, 1).Value = json("data")(0)("attributes")("legalName")("name") 'Entity Status (Active/Not Active)
But I only get error 438:
Full Code:
Sub getData()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet2") 'Set the outputdata sheet
Dim json As Object
Dim item As Object
Dim URL As String
Dim scriptControl As Object
Set scriptControl = CreateObject("MSScriptControl.ScriptControl")
scriptControl.Language = "JScript"
URL = "https://api.gleif.org/api/v1/lei-records?filter[lei]=5493001ZDI5KQPZTPI85"
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.send
Set json = scriptControl.Eval("(" + .responseText + ")")
'MsgBox scriptControl.Eval("(" + .responseText + ").data.attributes.lei")
.abort
End With
Dim jsent As Variant
ws.Cells(1, 1).Value = json("data")(0)("attributes")("legalName")("name") 'Entity LegalName
End Sub