0

I am having some difficulty parsing Google's pagespeed JSON response into a dataframe in R. Ideally I just want the dataframe to contain the speed metrics.

Code to get JSON response.

'''

library(httr)
library(jsonlite)
library(tidyverse)
library(rjson)

url <- "https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://www.google.com"


raw_json <- url %>% 
  httr::GET() %>% 
  httr::content()


df_pagespeed <-  fromJSON(raw_json$lighthouseResult %>% str(max.level = 2))  

'''

I get the following error '''

json_str must be a character string

'''

  • Your `raw_json` object has already been parsed by the `httr::content` function, so what you have is a list. When I run it, there is no member called `lighthouseResult`, but the main data member is called `loadingExperience` – Allan Cameron Jun 28 '22 at 16:58
  • Hello @AllanCameron thanks for the reply, it has saved me a lot of time. Sorry I am new to programming and R. Once I have figured out the code I will repost it in the comments. –  Jun 28 '22 at 20:55

0 Answers0