I am working with a JSON object in R. Actually my data looks like this:
#Data
v1 <- "{\"data\":{\"id\":25945306,\"full_name\":\"badgalriri\",\"username\":\"badgalriri\",\"profile_picture\":{\"normal\":\"https:\\/\\/scontent-frt3-1.cdninstagram.com\\/v\\/t51.2885-19\\/11032926_1049846535031474_260957621_a.jpg?_nc_ht=scontent-frt3-1.cdninstagram.com&_nc_ohc=Z3JOqyO0wu4AX8eB_8u&edm=ABfd0MgBAAAA&ccb=7-4&oh=1e3372e82cfecc3209fa9c16f90073f2&oe=615BCFBA&_nc_sid=7bff83\",\"hd\":\"https:\\/\\/scontent-frt3-1.cdninstagram.com\\/v\\/t51.2885-19\\/11032926_1049846535031474_260957621_a.jpg?_nc_ht=scontent-frt3-1.cdninstagram.com&_nc_ohc=Z3JOqyO0wu4AX8eB_8u&edm=ABfd0MgBAAAA&ccb=7-4&oh=1e3372e82cfecc3209fa9c16f90073f2&oe=615BCFBA&_nc_sid=7bff83\"},\"biography\":\"\",\"website\":\"http:\\/\\/ri-hanna.io\\/savagex\",\"figures\":{\"posts\":4787,\"followers\":109158907,\"followings\":1563},\"is_private\":false,\"is_verified\":true,\"is_business\":false,\"is_joined_recently\":false,\"has_channel\":false,\"reel\":{\"highlight\":{\"count\":17}},\"business\":{\"category\":null,\"phone\":null,\"email\":null,\"address\":null},\"facebook_page\":null},\"message\":\"OK\",\"code\":200}"
This is a very complex string to format and the only thing I could reach was this:
library(jsonlite)
#Code
v2 <- fromJSON(v1)
Where I get a list pretty formatted with three slots. I have tried to transform as dataframe the data slot but I got a error:
as.data.frame(v2$data)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 1, 0
Maybe due the fact that some slots have multiple elements:
v2$data$business
$category
NULL
$phone
NULL
$email
NULL
$address
NULL
How can I get all the elements from v2$Data formatted as dataframe, even including all elements in sublists (as those in previous list showed) as columns in the final dataframe.
Many thanks!