Skip to content

Commit 254fcd1

Browse files
committed
Update VBA-JSON to v2.0.1
1 parent 1fa8f76 commit 254fcd1

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/WebHelpers.bas

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ Private Declare Sub json_CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
221221
(json_MemoryDestination As Any, json_MemorySource As Any, ByVal json_ByteLength As Long)
222222

223223
#End If
224+
225+
Private Type json_Options
226+
' VBA only stores 15 significant digits, so any numbers larger than that are truncated
227+
' 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
228+
' See: http://support.microsoft.com/kb/269370
229+
'
230+
' By default, VBA-JSON will use String for numbers longer than 15 characters that contain only digits
231+
' to override set `JsonConverter.JsonOptions.UseDoubleForLargeNumbers = True`
232+
UseDoubleForLargeNumbers As Boolean
233+
234+
' The JSON standard requires object keys to be quoted (" or '), use this option to allow unquoted keys
235+
AllowUnquotedKeys As Boolean
236+
237+
' The solidus (/) is not required to be escaped, use this option to escape them as \/ in ConvertToJson
238+
EscapeSolidus As Boolean
239+
End Type
240+
Public JsonOptions As json_Options
224241
' === End VBA-JSON
225242

226243
#If Mac Then
@@ -1767,7 +1784,7 @@ Private Function web_GetUrlEncodedKeyValue(Key As Variant, Value As Variant) As
17671784
End Function
17681785

17691786
''
1770-
' VBA-JSON v2.0.0
1787+
' VBA-JSON v2.0.1
17711788
' (c) Tim Hall - https://github.com/VBA-tools/VBA-JSON
17721789
'
17731790
' JSON Converter for VBA
@@ -1813,23 +1830,6 @@ End Function
18131830

18141831
' (Declarations moved to top)
18151832

1816-
Private Type json_Options
1817-
' VBA only stores 15 significant digits, so any numbers larger than that are truncated
1818-
' 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
1819-
' See: http://support.microsoft.com/kb/269370
1820-
'
1821-
' By default, VBA-JSON will use String for numbers longer than 15 characters that contain only digits
1822-
' to override set `JsonConverter.JsonOptions.UseDoubleForLargeNumbers = True`
1823-
UseDoubleForLargeNumbers As Boolean
1824-
1825-
' The JSON standard requires object keys to be quoted (" or '), use this option to allow unquoted keys
1826-
AllowUnquotedKeys As Boolean
1827-
1828-
' The solidus (/) is not required to be escaped, use this option to escape them as \/ in ConvertToJson
1829-
EscapeSolidus As Boolean
1830-
End Type
1831-
Public JsonOptions As json_Options
1832-
18331833
' ============================================= '
18341834
' Public Methods
18351835
' ============================================= '
@@ -1901,7 +1901,7 @@ Public Function ConvertToJson(ByVal json_DictionaryCollectionOrArray As Variant)
19011901
ConvertToJson = """" & json_DateStr & """"
19021902
Case VBA.vbString
19031903
' String (or large number encoded as string)
1904-
If Not JsonConverter.JsonOptions.UseDoubleForLargeNumbers And json_StringIsLargeNumber(json_DictionaryCollectionOrArray) Then
1904+
If Not JsonOptions.UseDoubleForLargeNumbers And json_StringIsLargeNumber(json_DictionaryCollectionOrArray) Then
19051905
ConvertToJson = json_DictionaryCollectionOrArray
19061906
Else
19071907
ConvertToJson = """" & json_Encode(json_DictionaryCollectionOrArray) & """"
@@ -2172,7 +2172,7 @@ Private Function json_ParseNumber(json_String As String, ByRef json_Index As Lon
21722172
' See: http://support.microsoft.com/kb/269370
21732173
'
21742174
' Fix: Parse -> String, Convert -> String longer than 15 characters containing only numbers and decimal points -> Number
2175-
If Not JsonConverter.JsonOptions.UseDoubleForLargeNumbers And Len(json_Value) >= 16 Then
2175+
If Not JsonOptions.UseDoubleForLargeNumbers And Len(json_Value) >= 16 Then
21762176
json_ParseNumber = json_Value
21772177
Else
21782178
' VBA.Val does not use regional settings, so guard for comma is not needed
@@ -2187,7 +2187,7 @@ Private Function json_ParseKey(json_String As String, ByRef json_Index As Long)
21872187
' Parse key with single or double quotes
21882188
If VBA.Mid$(json_String, json_Index, 1) = """" Or VBA.Mid$(json_String, json_Index, 1) = "'" Then
21892189
json_ParseKey = json_ParseString(json_String, json_Index)
2190-
ElseIf JsonConverter.JsonOptions.AllowUnquotedKeys Then
2190+
ElseIf JsonOptions.AllowUnquotedKeys Then
21912191
Dim json_Char As String
21922192
Do While json_Index > 0 And json_Index <= Len(json_String)
21932193
json_Char = VBA.Mid$(json_String, json_Index, 1)
@@ -2243,7 +2243,7 @@ Private Function json_Encode(ByVal json_Text As Variant) As String
22432243
json_Char = "\\"
22442244
Case 47
22452245
' / -> 47 -> \/ (optional)
2246-
If JsonConverter.JsonOptions.EscapeSolidus Then
2246+
If JsonOptions.EscapeSolidus Then
22472247
json_Char = "\/"
22482248
End If
22492249
Case 8

0 commit comments

Comments
 (0)