How to parse Json data from webpage to excel sheet ?

ppnar007

New Member
Joined
Nov 22, 2022
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have made this program , I wanna parse webpage json data in excel rows and columns , I am getting error
I have imported json converter from file mentioned here : "Import Json to excel and export excel to Json (Updated 2022) - Coding is Love"
Please help me to parse this data

VBA Code:
Public Sub exceljson()
Dim http As Object, JSON As Object, i As Integer
Set http = CreateObject("MSXML2.XMLHTTP")

'original url = "https://www.crisilratings.com/en/home/our-business/ratings/rating-rationale.html"

sURL = "https://www.crisilratings.com/content/crisilratings/en/home/our-business/ratings/rating-rationale/_jcr_content/wrapper_100_par/ratingresultlisting.results.json?cmd=RR&start=0&limit=100&filters={}&_=1678267659258"


http.Open "GET", sURL, False
http.send

MsgBox http.responseText


Set JSON = ParseJson(http.responseText)

' ParseJson downloaded from

i = 2
For Each Item In JSON
Sheets("Output").Cells(i, 1).Value = Item("ratingDate")
Sheets("Output").Cells(i, 2).Value = Item("abstractTemp")
Sheets("Output").Cells(i, 3).Value = Item("companyCode")
Sheets("Output").Cells(i, 4).Value = Item("companyName")
Sheets("Output").Cells(i, 5).Value = Item("heading")
Sheets("Output").Cells(i, 6).Value = Item("ratingDate")
Sheets("Output").Cells(i, 7).Value = Item("showAbstarct")
Sheets("Output").Cells(i, 8).Value = Item("transDate")
i = i + 1
Next
MsgBox ("complete")
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Fairly easy if you use Power query
Power Query:
let
    Source = Json.Document(Web.Contents("https://www.crisilratings.com/content/crisilratings/en/home/our-business/ratings/rating-rationale/_jcr_content/wrapper_100_par/ratingresultlisting.results.json?cmd=RR&start=0&limit=100&filters={}&_=1678267659258")),
    docs = Source[docs],
    #"Converted to Table" = Table.FromList(docs, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"ratingDate", "companyCode", "prId", "heading", "abstractTemp", "showAbstarct", "ratingFileName", "transDate", "companyName", "industryName"}, {"Column1.ratingDate", "Column1.companyCode", "Column1.prId", "Column1.heading", "Column1.abstractTemp", "Column1.showAbstarct", "Column1.ratingFileName", "Column1.transDate", "Column1.companyName", "Column1.industryName"})
in
    #"Expanded Column1"
1678279202137.png
 
Upvote 0
Rescue the json items from docs object. I came up with this solution:
VBA Code:
 sGetResult = httpObject.ResponseText
 sGetResult = Left(sGetResult, InStrRev(sGetResult, "]"))
 sGetResult = Right(sGetResult, Len(sGetResult) - InStr(sGetResult, "[") + 1)
 
Upvote 0
Thanks all for your precious time , I have also written program in following way and its working nicely


VBA Code:
sURL = "https://www.crisilratings.com/content/crisilratings/en/home/our-business/ratings/rating-rationale/_jcr_content/wrapper_100_par/ratingresultlisting.results.json?cmd=RR&start=0&limit=100&filters={}&_=1678267659258"
 
 
    http.Open "GET", sURL, False
    http.send
 
    Set Json = ParseJson(http.responseText)
 
    Set c = ActiveSheet.Range("A1")
    j = 1
        For Each act In Json("docs")

            c.Resize(1, 11).Value = Array(j, act("ratingDate"), act("companyCode"), act("prId"), act("heading"), _
                                   act("abstractTemp"), act("showAbstarct"), act("ratingFileName"), act("transDate"), act("companyName"), act("industryName"))
                             
                                                        
            Set c = c.Offset(1, 0)
        j = j + 1
        Next act
 
Upvote 0
Solution

Forum statistics

Threads
1,214,594
Messages
6,120,436
Members
448,964
Latest member
Danni317

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