Skip to content

JSON format non convertible #234

Open
@Masfeir

Description

@Masfeir

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:

  1. removing brackets []
  2. adding quotations "" before and after the accolades
  3. doubling quotations on parameters ex ""AA""
  4. adding apostrophes '' to text values
  5. 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!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions