I have the same issue as in Excel VBA: Parsed JSON Object Loop but cannot find any solution. My JSON has nested objects so suggested solution like VBJSON and vba-json do not work for me. I also fixed one of them to work properly but the result was a call stack overflow because of to many recursion of the doProcess function.
The best solution appears to be the jsonDecode function seen in the original post. It is very fast and highly effective; my object structure is all there in a generic VBA Object of type JScriptTypeInfo.
The issue at this point is that I cannot determine what will be the structure of the objects, therefore, I do not know beforehand the keys that will reside in each generic objects. I need to loop through the generic VBA Object to acquire the keys/properties.
If my parsing javascript function could trigger a VBA function or sub, that would be excellent.
If you want to build on top of
ScriptControl, you can add a few helper method to get at the required information. TheJScriptTypeInfoobject is a bit unfortunate: it contains all the relevant information (as you can see in the Watch window) but it seems impossible to get at it with VBA. However, the Javascript engine can help us:A few notes:
JScriptTypeInfoinstance refers to a Javascript object,For Each ... Nextwon’t work. However, it does work if it refers to a Javascript array (seeGetKeysfunction).GetPropertyandGetObjectProperty.length,0,Item 0,1,Item 1etc. With the VBA dot notation (jsonObject.property), only the length property is accessible and only if you declare a variable calledlengthwith all lowercase letters. Otherwise the case doesn’t match and it won’t find it. The other properties are not valid in VBA. So better use theGetPropertyfunction.InitScriptEngineonce before using the other functions to do some basic initialization.