VBA JSON log in TXT ""

571 Views Asked by At

I finished macro that is sending request to API and getting reply in JSON format. The results are then returned to Sheet("results"). I am also creating separate log file. The problem is that the output is not in standard JSON format like:

    {
        "title": "Example Schema",
        "type": "object",
        "properties": {
            "firstName": {
                "type": "string"
            },
            "lastName": {
                "type": "string"
            },
            "age": {
                "description": "Age in years",
                "type": "integer",
                "minimum": 0
            }
        },
        "required": ["firstName", "lastName"]
    }

But does have "excel required" double quotes:

    "{
        ""title"": ""Example Schema"",
        ""type"": ""object"",
        ""properties"": {
            ""firstName"": {
                ""type"": ""string""
            },
            ""lastName"": {
                ""type"": ""string""
            },
            ""age"": {
                ""description"": ""Age in years"",
                ""type"": ""integer"",
                ""minimum"": 0
            }
        },
        ""required"": [""firstName"", ""lastName""]
    }"

My macro looks like (bit truncated):

'output path
Dim FF As Integer
    FF = FreeFile
Dim FilePath As String

   FilePath = ActiveWorkbook.Path & "\Log" & Format(Now(), "yyyymmdd") & ".txt"

Open FilePath For Append As FF

sJson = ""
'turncated here ...


ObjHttp.Open "POST", sURL, False
ObjHttp.setRequestHeader "Content-Type", "application/json"
ObjHttp.send (sJson)
xmlDoc.LoadXML (ObjHttp.responseText)

'log
 Dim LastRow As Long
 With ThisWorkbook.Sheets("Result")
      LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
 End With

Sheets("Result").Cells(LastRow + 1, 1) = Now()
Sheets("Result").Cells(LastRow + 1, 2) = ObjHttp.responseText

Write #FF, ObjHttp.responseText

Next i

Close #FF

End Sub

What do I need to change in order to remove double quote marks?

Many thanks in advance.

1

There are 1 best solutions below

0
On

This one replaces double quotes marks to singe quotes

Dim findChars, replaceChars As String

findChars = """"""

replaceChars = """"

Replace(ObjHttp.responseText, findChars, replaceChars)