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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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,215,430
Messages
6,124,852
Members
449,194
Latest member
HellScout

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