Description
Hi everyone, I'm brand new on GitHUB, VBA, and coding in general but I'm very excited to be here. I'm tasked to extract data from a web API on excel, which is why I tried using the JsonConverter (thanks for building it). Now here's my issue: running the VBA pops execution errors (450, 5, or other) it changes every time I fix the script. The JSON format is similar to the following:
[{"AA":"AAtext","BB":"BBtext","CC":"CCnumber"}] (you get the gist of it)
Now when I run it like this it shows an error. But, I tried to change the format to match the example from the README.md file and the script ran just fine outputting the expected values. The successful format is as follows:
"{""AA"":'AAtext',""BB"":'BBtext',""CC"":CCnumber}"
Changes made:
- removing brackets []
- adding quotations "" before and after the accolades
- doubling quotations on parameters ex ""AA""
- adding apostrophes '' to text values
- removing quotations "" from number values
Quite frankly I don't understand what the issue is, I am unable to share my actual code because of data ownership and sensitivity, but here's a snippet of what it looks like:
.................................................................................................................................................................................................................................
Sub Beta()
' Simple script for data extraction
Dim url As String, parameters As String
url = "..."
parameters = "..."
' Set the request
Dim request As New WinHttpRequest
request.Open "Get", url & parameters
request.SetRequestHeader "Accept", "text/json"
request.SetRequestHeader "Authorization", "key"
' Send request
request.Send
' Response JSON verification
If request.Status <> 200 Then
MsgBox "Error" & request.responseText
Exit Sub
End If
' Parse the JSON
Dim response As Object
Set response = JsonConverter.ParseJson([{"AA":"AAtext","BB":"BBtext","CC":"CCnumber"}]) A
'Set response = JsonConverter.ParseJson("{""AA"":'AAtext',""BB"":'BBtext',""CC"":CCnumber}") B
Debug.Print response("CCnumber")
End Sub
.................................................................................................................................................................................................................................
A is the original extracted JSON format from the API -> does not work
B is the modified JSON format yielding the right answer from CCnumber
Any help figuring this out is much appreciated, thanks in advance and thanks again for building the JsonConverter!!