0

I have JSON data in this form [{"word":"something", "id":1023] How can I get the value of word from the JSON data using Visual Basic? Thanks.

1
  • 2
    Use a JSON parser - Tim Hall wrote a pretty nice one, it's on GitHub Commented Jan 10, 2019 at 19:52

1 Answer 1

1

Grab a copy of this project, add it to your VBA project. You'll need to add a reference to Microsoft Scripting Runtime for this to work as the results from the parsed string get stored in a Dictionary. Once that's done, you can parse JSON, like this:

Sub ParseSomeJson()
    Dim jsonString As String
    Dim json As Object
    jsonString = "{""word"":""something"", ""id"":1023}" 'I adjusted this 
    Set json = JsonConverter.ParseJson(jsonString)
    Debug.Print json("word"), json("id")
End Sub

You'll get back:

something      1023 
Sign up to request clarification or add additional context in comments.

1 Comment

Note that Tim Hall also wrote a drop-in replacement for Scripting.Dictionary (also found under that VBA-TOOLS GitHub org), that works off the Scripting Runtime on Windows, and works on a Mac.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.