Error loading dataframe with JSON file data

Asked

Viewed 58 times

1

I am getting the error below when loading a JSON file to a dataframe.

Error in (Function (..., Row.Names = NULL, check.Rows = FALSE, check.Names = TRUE, : Arguments imply differing number of Rows: 1, 0

What would be the best way to load this data into a dataframe and get around this error?

Code executed:

install.packages(rjson)
library(rjson)

json_file <- "D:\\app_smart.json"
json_data <- fromJSON(file=json_file)
df = as.data.frame(json_data$`_source`)

Sample data from JSON file (5 first lines):

{"_index":"app_smart","_type":"doc","_id":"gross549131","_score":1,"_source":{"id":549131,"sale_type":"PLAN","sale_segment":"CONTROL","plan_name":"APP CONTROL Z PLUS","sale_value":49.99,"user_id":null,"user_name":null,"user_cpf":00923359444,"user_registration":"3318641","place_id":null,"place_cust_code":"Não Informado","view_executiva":null,"view_oficial":null,"view_gerencial":null,"place_coordinator_cpf":null,"supervisor_cpf":null,"channel_slug":null,"origem":"grosslogin","quantity_weight":1,"billing_weight":1,"sale_date":"2019-11-21T00:00:00-03:00","sale_created_at":"2019-12-02T09:41:03-03:00","sale_updated_at":"2019-12-02T09:41:03-03:00"}}
{"_index":"app_smart","_type":"doc","_id":"gross549138","_score":1,"_source":{"id":549138,"sale_type":"PLAN","sale_segment":"CONTROL","plan_name":"APP CONTROL SMART 1","sale_value":64.99,"user_id":null,"user_name":null,"user_cpf":null,"user_registration":"3508484","place_id":null,"place_cust_code":"Não Informado","view_executiva":null,"view_oficial":null,"view_gerencial":null,"place_coordinator_cpf":null,"supervisor_cpf":null,"channel_slug":null,"origem":"grosslogin","quantity_weight":1,"billing_weight":1,"sale_date":"2019-11-21T00:00:00-03:00","sale_created_at":"2019-12-02T09:41:03-03:00","sale_updated_at":"2019-12-02T09:41:03-03:00"}}
{"_index":"app_smart","_type":"doc","_id":"gross549139","_score":1,"_source":{"id":549139,"sale_type":"PLAN","sale_segment":"CONTROL","plan_name":"APP CONTROL SMART 1","sale_value":129.98,"user_id":null,"user_name":null,"user_cpf":null,"user_registration":"3520701","place_id":null,"place_cust_code":"Não Informado","view_executiva":null,"view_oficial":null,"view_gerencial":null,"place_coordinator_cpf":null,"supervisor_cpf":null,"channel_slug":null,"origem":"grosslogin","quantity_weight":1,"billing_weight":1,"sale_date":"2019-11-21T00:00:00-03:00","sale_created_at":"2019-12-02T09:41:03-03:00","sale_updated_at":"2019-12-02T09:41:03-03:00"}}
{"_index":"app_smart","_type":"doc","_id":"gross549154","_score":1,"_source":{"id":549154,"sale_type":"PLAN","sale_segment":"CONTROL","plan_name":"APP CONTROL SMART 2019","sale_value":64.99,"user_id":null,"user_name":null,"user_cpf":12645302262,"user_registration":"3520701","place_id":null,"place_cust_code":"Não Informado","view_executiva":null,"view_oficial":null,"view_gerencial":null,"place_coordinator_cpf":null,"supervisor_cpf":null,"channel_slug":null,"origem":"grosslogin","quantity_weight":1,"billing_weight":1,"sale_date":"2019-11-21T00:00:00-03:00","sale_created_at":"2019-12-02T09:41:03-03:00","sale_updated_at":"2019-12-02T09:41:03-03:00"}}
{"_index":"app_smart","_type":"doc","_id":"gross549155","_score":1,"_source":{"id":549155,"sale_type":"PLAN","sale_segment":"CONTROL","plan_name":"APP PRE SMART","sale_value":64.99,"user_id":null,"user_name":null,"user_cpf":null,"user_registration":"3534316","place_id":null,"place_cust_code":"Não Informado","view_executiva":null,"view_oficial":null,"view_gerencial":null,"place_coordinator_cpf":null,"supervisor_cpf":null,"channel_slug":null,"origem":"grosslogin","quantity_weight":1,"billing_weight":1,"sale_date":"2019-11-21T00:00:00-03:00","sale_created_at":"2019-12-02T09:41:03-03:00","sale_updated_at":"2019-12-02T09:41:03-03:00"}}
No answers

Browser other questions tagged

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