Accessing values in a JSON object

PrashanthKumar123

New Member
Joined
May 1, 2021
Messages
38
Hi - I am looking to call an API from VBA. The response is a JSON object. Using .responsetext, I am able to extract contents, but I presume this converts into a text string. Is there a better way to access items inside the object?

My code as below:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function API_call(i As String) As Object
Url = "https://api.brandsome.io/search?q=" & i

Set API_call = CreateObject("MSXML2.serverXMLHTTP")

API_call.Open "GET", Url, False
API_call.send

API_call_brandname = API_call.responsetext
Debug.Print API_call_brandname

End Function

'Calling the function

Sub test()
Dim i As String
i = "Swiggy"
API_call (i)
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

JSON response to above example

{"status":true,"data":{"_id":"60a2dad9db064721c0da6e71","brand_name":"Swiggy","brand_domain":"swiggy.com","brand_logo":"https://play-lh.googleusercontent.c...1FrMdrg8jooV9ftDidkOhnKNWacfPhjKae1IA=s180-rw"}}
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,​
as the response is not an object but just some text so the VBA text functions can be used easily …​
 
Upvote 0
yes, I can use text functions

I am keen to understand if the API response can be handled as object directly, without having to use .responsetext and converting to text
 
Upvote 0
No need to convert to text as responseText is already a text ‼​
So can not be neither « handled as object directly » as this is not an object but text !​
This text can be converted to some object via a Java script for example as you can find on blogs or forums.​
You can find also on net some 'big mama factory gas' JSon VBA add-in …​
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top