Hi all,
I'm using this module to help with converting dictionaries to a JSON based string output.
https://github.com/VBA-tools/VBA-JSON
However I've run into a situation where I need to use unquoted keys to match an expected format.
https://echarts.apache.org/examples/...=sankey-simple
Unquoted keys is an option in VBA-JSON, but it doesn't seem to work.
I tried this:
Public Sub Data2SankeyJSOs()
Dim ws As Worksheet
Set ws = Sheet31
Dim loSankeys As ListObject
Set loSankeys = ws.ListObjects("tSankeys")
Dim SankeyDict As Dictionary
Dim rw As Long
Dim JSONstr As String
For rw = 1 To loSankeys.ListRows.Count
Set SankeyDict = Table2Dictionary(ws, loSankeys, 1) 'helper function creates dictionary from tables
'*********
JsonConverter.JsonOptions.AllowUnquotedKeys = True 'IS THIS CORRECT??? DOESN'T MAKE A DIFFERENCE
'**********
JSONstr = JsonConverter.ConvertToJson(SankeyDict, Whitespace:=0)
Let JSONstr = "option = {" & vbNewLine & "series: " & vbNewLine & JSONstr & vbNewLine & "};"
Let JSONstr = Replace(JSONstr, Chr(34), Chr(39))
loSankeys.ListColumns("JSON").DataBodyRange(rw).Value = JSONstr
loSankeys.ListColumns("JSON").DataBodyRange(rw) = False
Next rw
End Sub
How do I correctly set an option for the VBA-JSON object?
Here is the explanation from the documentation:
"Options
VBA-JSON includes a few options for customizing parsing/conversion if needed:
UseDoubleForLargeNumbers (Default = False) VBA only stores 15 significant digits, so any numbers larger than that are truncated. This can lead to issues when BIGINT's are used (e.g. for Ids or Credit Cards), as they will be invalid above 15 digits. By default, VBA-JSON will use String for numbers longer than 15 characters that contain only digits, use this option to use Double instead.
AllowUnquotedKeys (Default = False) The JSON standard requires object keys to be quoted (" or '), use this option to allow unquoted keys.
EscapeSolidus (Default = False) The solidus (/) is not required to be escaped, use this option to escape them as \/ in ConvertToJson.
example
JsonConverter.JsonOptions.EscapeSolidus = True"
What am I doing wrong?
Note, I didn't share the example workbook as it is large and complex.
Everything is working correctly including the creation of a JSON style string. I just need to know how to get the unquoted option to work, or write a function to remove quotes left of each ":"
Thanks
Bookmarks