VBA-tools / VBA-JSON

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

Issue: try to use JsonConverter.ConvertToJson fuction to convert,but String value becomes Integer #270

Open Douglas87 opened 3 months ago

Douglas87 commented 3 months ago

I want to convert a Json bject to String,so I used JsonConverter.ConvertToJson fuction

my test case Json object is {"stringKey":"2024051090001075"} after use JsonConverter.ConvertToJson, my expect str is {"stringKey":"2024051090001075"}, but got {"stringKey":2024051090001075}

Nick-vanGemeren commented 3 months ago

' 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 ' See: http://support.microsoft.com/kb/269370 ' ' By default, VBA-JSON will use String for numbers longer than 15 characters that ' contain only digits ' to override set JsonConverter.JsonOptions.UseDoubleForLargeNumbers = True

The option description applies to parsing from a JSON string. But for consistency the equivalent actions are used in the other direction when converting to JSON.

So counter-intuitively (since you aren't using Double), to keep your string value, make the option True before calling ConvertToJson.

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