VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.79k stars 573 forks source link

{"A": []"B": []} is parsable, although its not valid JSON #207

Open ReneNyffenegger opened 3 years ago

ReneNyffenegger commented 3 years ago

The following JSON document is parsed by VBA-JSON, although it is not valid JSON (because the B key is not separated by a comma from the A key):

{"A": []"B": []}

The following VBA sub indicates that that document has the keys A and B:

Option Explicit

Sub jsonTest()

    Dim jsonText As String
    jsonText = "{" & _
    """A"": []" & _
    """B"": []" & _
    "}"

    Debug.Print jsonText

    Dim jsonParsed As dictionary
    Set jsonParsed = ParseJson(jsonText)

    Dim k As Variant
    For Each k In jsonParsed
        Debug.Print "key        = " & k
    Next k

End Sub
Deedolith commented 2 years ago

This is due to the internal json_ParseObject function that do not check for the absence of a comma between 2 members.

IMO the operation should be aborted (by raising an error) when such case happen. Alas, I don't think it will be fixed any time soon, as the library do not seems to be maintained anymore.