Problem converting JSON to dataframe in R

Asked

Viewed 40 times

1

I want to extract a JSON content from a website and convert it into a dataframe

Website is https://schutz-shoes.com/products/amaia-sandal-metallic-leather?color=ouro%20gold

Inside that site, squeezing F12, and going into Network, get a link to the API that brings the price of the product, given in the link below

https://schutz-shoes.com/tools/verge-json-ld?url=https://schutz-shoes.com/products/amaia-sandal-metallic-leather?color=ouro%20gold

That’s the API I want to extract content from JSON for a data.frame

I tried the following method

library(httr)
library(jsonlite)

a<-GET("https://schutz-shoes.com/tools/verge-json-ld?url=https://schutz-shoes.com/products/amaia-sandal-metallic-leather?color=ouro%20gold")
a<-content(a,"text")
b<-fromJSON(a)

But I get the following error

Error in parse_con(txt, bigint_as_char) : 
  lexical error: invalid character inside string.
          ail and walk-able chunky heel.  Material: Metallic Leather H
                     (right here) ------^

I’d like to get around the mistake, but I don’t know the source of the problem.

1 answer

1

I managed to solve the problem, I will leave here the solution

The encoding was missing, because the site is not Brazilian

library(httr)
library(jsonlite)

a<-GET("https://schutz-shoes.com/tools/verge-json-ld?url=https://schutz-shoes.com/products/amaia-sandal-metallic-leather?color=ouro%20gold")
a<-content(a,type = "text",encoding = "ISO-8859-1")
b<-fromJSON(a)
  • Good to know the problem has a solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.