I am currently attempting to parse JSON using the VBA module add in found here. I currently have JSON files stored as text documents locally, so I call them into VBA, make the necessary changes, and then send them back to a new file. For reasons I cannot figure out, it seems that the code is adding quotation marks at the beginning and end (because it is a string) and also adding quotes to every key/value pair. The later is a show-stopper for what I am trying to do (these are large Json Files). The Solution I have currently is to print them into a cell, and then re copy/paste the JSON into a text file, and even that is not very straightforward. Is there a solution to this problem that is better than what I am trying?
Dim Json As Object
FilePath = "Path to file.txt"
Open FilePath For Input As #1
Data = Input$(LOF(1), #1)
Close #1
Set Json = JsonConverter.ParseJson(Data)
Json("key 1")("key 2") = "value"
outputfile ="path to file.txt"
Write #1, JsonConverter.ConvertToJson(Json, Whitespace:=2)
Close #1
Open outputfile For Input As #1
NewData = Input$(LOF(1), #1)
Close #1
NewData = Replace(NewData, """", "!")
NewData = Replace(NewData, "!!", """")
NewData = Replace(NewData, "!", "")
m1.Cells(x,y) = NewData
So If you look at the input JSON vs the outputfile JSON, the key is successfully edited, but it looks like this
input file
{"key1":{"key2":"Blank"}}
outputfile
"{""key1"":{""key2"":""value""}}"
The files are much to large to post here, so removing the extra quotes from the keys and values, and the outside is a bear, and excel's replace function seems ill suited for this.
Like I said, the 3 lines of code starting with NewData handle this, and then the 4th line after that pastes the whole thing into a single cell, which I then paste back into a text file. This is the most efficient way I have come up with to remove both types of unwanted quotes.