Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneously trying to process objects as arrays #259

Open
Syakado opened this issue Nov 20, 2023 · 2 comments
Open

Erroneously trying to process objects as arrays #259

Syakado opened this issue Nov 20, 2023 · 2 comments

Comments

@Syakado
Copy link

Syakado commented Nov 20, 2023

Hello Guys.

Allow me to use a translation tool.

If you try to parse JSON of the following format,
json_ParseKey branch and I get Err.Raise 10001.
I want to solve the problem of processing an array as a key, since it is not a wrong JSON format.
Can you help me?

Function test()
    Dim target As String
    target = "[ {'List': [ '11111' ] } ]"
    Dim json As Dictionary
    Set json = JsonConverter.ParseJson(target)
End Function
@houghtonap
Copy link

You need to reread the project readme as well as Microsoft's website on the VBA.Collection and Scripting.Dictionary objects. VBA-JSON maps a Javascript Array to a VBA.Collection and a Javascript Object to a Scripting.Dictionary.

Your sample Javascript document is a Javascript Array, but you declared the variable to hold the return value as a Scripting.Dictionary which is not the correct object that matches your Javascript document. Also, in VBA you need to use the Set command to set the value of an object. See also, Microsoft VBA Reference on their website.

Hope that helps.

@Nick-vanGemeren
Copy link

Andrew, are you having issues with your chatbot? ;} Javascript is not relevant here.

Syakado, the text string you provided does not give an error 10001 (with version v2.3.2). It does give an error 13 (Type mismatch). After fixing Dim json As Object the function works as expected.
If you are getting error 10001 in json_ParseKey with a different text, then there is something wrong with a key:value pair; the error message text is more specific. Examples are:

  • {"key" value} - missing colon
  • {"key: value} - missing closing quote
  • {key: value} - only valid if you set JsonOptions.AllowUnquotedKeys

The ECMA standard specifies that a key is a string enclosed in double quotes. Unquoted single-word keys and keys using single quotes {'key': value} are VBA-JSON extensions. VBA-JSON does not support non-unique keys.

You cannot use a JSON Object or a JSON Array as a key, unless you encode it as a quoted string.

==========
If this solves your problem, please close the issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants