Hi all,

Take the following code example:

Sub ExcelForum()
Dim H As Object, J As Object, S As Object
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
    H.SetAutoLogonPolicy 0
    H.Open "GET", "https://jsonplaceholder.typicode.com/users"
    H.Send
    
Set S = CreateObject("ScriptControl")
    S.Language = "JScript"

Set J = S.Eval("(" + H.ResponseText + ")")
End Sub
This will set object J as a JSON object, parsing the json string found on https://jsonplaceholder.typicode.com/users
For field '0', the name is "Leanne Graham" - I can get this by saying:

Debug.Print CallByName(CallByName(J, 0, VbGet), "name", VbGet)
I can change this using the VbSet argument of CallByName, for example like this:
Debug.Print CallByName(CallByName(J, 0, VbGet), "name", VbSet, "Excel Forum")
Which changes the name from "Leanne Graham" to "Excel Forum".

This is all great, but what if I want to *add* a field? How could I add a new key/value pair?
For example - adding in "gender" as key, and "female" as a value - is that possible using CallByName?
If not, is it possible through JScript code added by "addcode"?

Essentially, this example code gives 10 names, but I'd want to be flexible to add a) key/values to each of the 10, and b) add additional name fields, with all subfields to the 10, increasing the total.

Please let me know if you have any bright ideas.
Thanks!

Jasper

ps: I know 'eval' isn't safe, I use a json parse emca 3 jscript function instead, but for ease of this example, I used 'eval'
ps ps: I know scriptcontrol isn't available in 64 bit - In reality I use a class module that sets it up either through MSHTA or straight to scriptcontrol, depending on the environment, but again, for ease of this example I just set the object straight to 'scriptcontrol'