VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.74k stars 565 forks source link

Will no process leading/trailing JSON brackets [] #254

Open jpmbiz70 opened 11 months ago

jpmbiz70 commented 11 months ago

JSON spec includes a leading/trailing bracket. It is an array of objects. Subsequently, Microsoft VBA throws a "Run-time error '424: Object required" error. If I remove the leading/trailing brackets it works fine. This either appears to be a bug in VBA for Excel or this tool.

Nick-vanGemeren commented 11 months ago

The JSON array [a,b,c ...] is a (possibly empty) list of JSON values, not necessarily JSON objects. It's not clear what your issue is. Can you post a simple code example which reproduces the problem?

TomasDohnal7 commented 11 months ago

The error can be reproduced, if you try to parse JSON: { "_Issues": "Issues", "description": "description", "id": "123", "milestonesList": "", "modulesList": "Module1", "priority": "", "projects": [ { } ], "projectsNamesList": "affas", "requirementsEstimate": "", "requirementsID": "2977", "requirementsLevel1": "Req1", "requirementsLevel2": "Req2", "requirementsLevel3": "blavla zak\u00e1zat", "requirementsProjectName": "Future", "requirementsState": "Sleeping", "requirementsTitle": "Something zak\u00e1zat", "sprint": ".4-Someday", "state": "Sleeping", "typeB": "Suggestion" }

Nick-vanGemeren commented 11 months ago

I did ask for a code example, not just the long input string. This routine:

Sub Issue254()
    Dim str As String
    Dim result As Object
    str = "{ ""_Issues"": ""Issues"", ""description"": ""description"", ""id"": ""123"", " _
        & "  ""milestonesList"": """", ""modulesList"": ""Module1"", ""priority"": """", " _
        & "  ""projects"": [ { } ], ""projectsNamesList"": ""affas"", " _
        & "  ""requirementsEstimate"": """", " _
        & "  ""requirementsID"": ""2977"", ""requirementsLevel1"": ""Req1"", " _
        & "  ""requirementsLevel2"": ""Req2"", ""requirementsLevel3"": ""blavla zak\u00e1zat"", " _
        & "  ""requirementsProjectName"": ""Future"", ""requirementsState"": ""Sleeping"", " _
        & "  ""requirementsTitle"": ""Something zak\u00e1zat"", ""sprint"": "".4-Someday"", " _
        & "  ""state"": ""Sleeping"", ""typeB"": ""Suggestion"" } "
    Set result = ParseJson(str)
    Debug.Print ConvertToJson(result, 2)
End Sub

... using VBA-JSON v2.3.2, runs without problems and prints as expected:

{
  "_Issues": "Issues",
  "description": "description",
  "id": "123",
  "milestonesList": "",
  "modulesList": "Module1",
  "priority": "",
  "projects": [
    {
    }
  ],
  "projectsNamesList": "affas",
  "requirementsEstimate": "",
  "requirementsID": "2977",
  "requirementsLevel1": "Req1",
  "requirementsLevel2": "Req2",
  "requirementsLevel3": "blavla zak\u00E1zat",
  "requirementsProjectName": "Future",
  "requirementsState": "Sleeping",
  "requirementsTitle": "Something zak\u00E1zat",
  "sprint": ".4-Someday",
  "state": "Sleeping",
  "typeB": "Suggestion"
}

Did you remember that you need a Set command to receive the object returned by ParseJson?

If the above solves your problem, please close the issue.

jpmbiz70 commented 11 months ago

if str = "[{ ""Issues"": ""Issues"", ""description"": ""description"", ""id"": ""123"", "

    & "  ""milestonesList"": """", ""modulesList"": ""Module1"", ""priority"": """", " _
    & "  ""projects"": [ { } ], ""projectsNamesList"": ""affas"", " _
    & "  ""requirementsEstimate"": """", " _
    & "  ""requirementsID"": ""2977"", ""requirementsLevel1"": ""Req1"", " _
    & "  ""requirementsLevel2"": ""Req2"", ""requirementsLevel3"": ""blavla zak\u00e1zat"", " _
    & "  ""requirementsProjectName"": ""Future"", ""requirementsState"": ""Sleeping"", " _
    & "  ""requirementsTitle"": ""Something zak\u00e1zat"", ""sprint"": "".4-Someday"", " _
    & "  ""state"": ""Sleeping"", ""typeB"": ""Suggestion"" }] "

It will fail. brackets need to be processed according to spec. Other tools like https://beautifytools.com/ will parse with brackets properly. But, I'm not sure if this is a MS issue or an issue with VBA-JSON.

Regards,

James


From: Nick van Gemeren @.> Sent: Tuesday, September 12, 2023 7:42 AM To: VBA-tools/VBA-JSON @.> Cc: James @.>; Author @.> Subject: Re: [VBA-tools/VBA-JSON] Will no process leading/trailing JSON brackets [] (Issue #254)

I did ask for a code example, not just the long input string. This routine:

Sub Issue254() Dim str As String Dim result As Object str = "{ ""Issues"": ""Issues"", ""description"": ""description"", ""id"": ""123"", " & " ""milestonesList"": """", ""modulesList"": ""Module1"", ""priority"": """", " & " ""projects"": [ { } ], ""projectsNamesList"": ""affas"", " & " ""requirementsEstimate"": """", " & " ""requirementsID"": ""2977"", ""requirementsLevel1"": ""Req1"", " & " ""requirementsLevel2"": ""Req2"", ""requirementsLevel3"": ""blavla zak\u00e1zat"", " & " ""requirementsProjectName"": ""Future"", ""requirementsState"": ""Sleeping"", " & " ""requirementsTitle"": ""Something zak\u00e1zat"", ""sprint"": "".4-Someday"", " _ & " ""state"": ""Sleeping"", ""typeB"": ""Suggestion"" } " Set result = ParseJson(str) Debug.Print ConvertToJson(result, 2) End Sub

... using VBA-JSON v2.3.2, runs without problems and prints as expected:

{ "_Issues": "Issues", "description": "description", "id": "123", "milestonesList": "", "modulesList": "Module1", "priority": "", "projects": [ { } ], "projectsNamesList": "affas", "requirementsEstimate": "", "requirementsID": "2977", "requirementsLevel1": "Req1", "requirementsLevel2": "Req2", "requirementsLevel3": "blavla zak\u00E1zat", "requirementsProjectName": "Future", "requirementsState": "Sleeping", "requirementsTitle": "Something zak\u00E1zat", "sprint": ".4-Someday", "state": "Sleeping", "typeB": "Suggestion" }

Did you remember that you need a Set command to receive the object returned by ParseJson?

If the above solves your problem, please close the issue.

— Reply to this email directly, view it on GitHubhttps://github.com/VBA-tools/VBA-JSON/issues/254#issuecomment-1715651604, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AH5ESYMYCORVS4EP3GYPO5DX2BKDZANCNFSM6AAAAAA4POVN7I. You are receiving this because you authored the thread.Message ID: @.***>

Nick-vanGemeren commented 11 months ago

Using your string (or adding surrounding square brackets to the original) to the test routine I posted earlier gives expected results on my system.

Are you on a Mac or using Dictionary.cls?

'It will fail' is as unhelpful as 'It doesn't work'. If you parse the string with the VBA Debugger, which code line in which sub/function raises the 424 error?