I'm using excel to modify existing JSON with the VBA-JSON library and I'm effectively trying to do what .push from javascript does, adding another entry to the nested array.
There's this previously posted question which illustrates what I'm trying to do but in the scope of creating a JSON file.
VBA-JSON Create nested objects
The accepted answer while helpful, doesn't show me how to add to what I already have without rebuilding it entirely. I can picture a mess of loops to parse my existing file into strings, then do something similar to what is in the post. I'm curious if there's another way to do it.
'download json
Set json = JsonConverter.ParseJson(H.responseText)
Debug.print json(1)("entries")(1)("Date")
'2019-09-25
json(1)("entries")(2)("Date") = "2019-09-26"
'error 9 Subscript out of Range
'upload json
[
{
"Entries": [
{
"Date": 2019-09-25,
"a": 1,
"b": 2
}
]
}
]
I'm able to access and modify existing entries but not add to it. I'm guessing this is because the library parses it as a defined array rather than variable? Any ideas on a simple solution or will I have to deconstruct my file into dictionaries/collections and rebuild it first?