Check if a string is valid json string using VBA excel

Viewed 294

I don't know the contents of JSON like the key-value pair so is there any method that we can use to know if the JSON string is valid or not using VBA excel.

The json looks like this

{
    "menu": "food",
    "open": "true",
    "order": "true",
    "food": [
        {
            "name": "burger",
            "type": "saucy",
            "id": 1,
            "available": true,
            "price": "3$"
        },
        {
            "name": "pizza",
            "type": "spicy",
            "id": 2,
            "available": true,
            "price": "2$"
        }
    ]
}
1 Answers

You could try and parse your json file with VBA-tools/VBA-JSON

Dim Json As Object
Set Json = JsonConverter.ParseJson("{""a"":123,""b"":[1,2,3,4],""c"":{""d"":456}}")

JSON conversion and parsing for VBA (Windows and Mac Excel, Access, and other Office applications).
It grew out of the excellent project vba-json, with additions and improvements made to resolve bugs and improve performance (as part of VBA-Web).

I understand from your previous question that you "don't want to use a GitHub project nor use Power Query but I am not able to get any proper reference on how to do it."

Here is a proper reference:

You can see it in action with "Excel VBA: Parse JSON, Easily" from Daniel Ferry

Related