mdJson.bas (github too) is an x64 and 32-bit implementation of JSON parsing/dumping functions that are using instances of built-in VBA.Collection to represent both composite JSON objects and arrays. The module allows to switch to alternative internal representation using Scripting.Dictionary for the JSON objects/arrays although these usually require more memory and are slower for data above certain size.
To remain agnostic to this dual internal representation the module implements an accessor property JsonValue for getting and modifying JSON object properties (e.g. JsonValue(oJson, "path/to/key") = 42) and JsonKeys to enumerate JSON object keys (this works for arrays too).
JsonValue can be used with "wildcard" accessor expression like this vArray = JsonValue(oJson, "receiver/phones/*/number") to return array of numbers from all entries in the phones JSON array.
JsonValue and JsonKeys support JSON Path expressions too (except some advanced features like deep scan, array slices and functions). More info on JSON Path Expressions (SQL Server) too.
JSON Path expressions can use the dot–notation
JsonValue(oJson, "$.store.book[0].title")
or the bracket–notation
JsonValue(oJson, "$['store']['book'][0]['title']")
Another set of helper functions are JsonTo/FromXmlDocument which as the names suggest can be used to transcode to/from XML (e.g. when accessing SOAP services).
cheers,Code:'--- mdJson.bas Option Explicit DefObj A-Z Private Const MODULE_NAME As String = "mdJson" #Const ImplScripting = JSON_USE_SCRIPTING <> 0 #Const ImplUseShared = DebugMode <> 0 #Const HasPtrSafe = (VBA7 <> 0) #Const LargeAddressAware = (Win64 = 0 And VBA7 = 0 And VBA6 = 0 And VBA5 = 0) '--- See gist in link above '--- https://gist.github.com/wqweto/e92dce63a68cd3ff9ca91b053b9510c9
</wqw>




Reply With Quote