Skip to content

theredstapler/VBA-JSON

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VBA-JSON

JSON conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications). It grew out of the excellent project vba-json, with additions and improvements made to resolve bugs and improve performance (as part of VBA-Web).

Tested in Windows Excel 2013 and Excel for Mac 2011, but should apply to 2007+.

  • For Windows-only support, include a reference to "Microsoft Scripting Runtime"
  • For Mac and Windows support, include VBA-Dictionary.

Example

Dim Json As Object
Set Json = JsonConverter.ParseJSON("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")

' Json("a") -> 123
' Json("b")(2) -> 2
' Json("c")("d") -> 456
Json("c")("e") = 789

Debug.Print JsonConverter.ConvertToJson(Json)
' -> "{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456,""e"":789}}"

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.
JsonConverter.JsonOptions.EscapeSolidus = True

Installation

  1. Download the latest release
  2. Import JsonConverter.bas into your project (Open VBA Editor, Alt + F11; File > Import File)

About

JSON conversion and parsing for VBA

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Visual Basic .NET 100.0%