How to implement guide with using `purrr::map()` to extract nested json data in r - unexpected list structure
I'm trying to extract values from a nested JSON object using the `purrr` package in R, but I'm working with an unexpected list structure that I'm struggling to work with... Here's a simplified version of the JSON I'm dealing with: ```json { "data": [ { "id": 1, "attributes": { "name": "Item One", "details": { "description": "First item description", "price": 100 } } }, { "id": 2, "attributes": { "name": "Item Two", "details": { "description": "Second item description", "price": 150 } } } ] } ``` I want to extract the names and prices of each item into a tidy data frame. So I wrote the following R code: ```r library(jsonlite) library(purrr) library(dplyr) json_data <- fromJSON("path/to/your/data.json") # my attempt to extract names and prices result <- json_data$data %>% map_df(~ tibble( name = .x$attributes$name, price = .x$attributes$details$price )) ``` However, I'm getting an behavior message: `behavior in UseMethod("as.data.frame"): no applicable method for 'as.data.frame' applied to an object of class "list"`. It seems like the `map_df` function is not returning what I expect. I even tried using `map()` instead of `map_df()`, but that just returned a list of tibbles, which isn't what I need. I've also checked the structure of the `json_data$data` and it appears to be a list of lists, but I'm not sure how to properly flatten it into a data frame. Is there a better way to do this, or am I missing something in my current implementation? Any help would be greatly appreciated! This is for a mobile app running on Ubuntu 20.04. What am I doing wrong?