Testjson Version 2 example

#read json file and change it into flattern tabular format
require(RJSONIO)
library(dplyr)
json_data = NULL
json_data <- fromJSON(file= “https://api.iextrading.com/1.0/stock/aapl/chart/date/20181123” )
print(length(json_file))
#df <- do.call(“rbind.fill”, lapply(json_data, as.data.frame))
df <- bind_rows(json_data)
#df <- as_data_frame(jsd)
View(df)
remove(json_data)

################################———————————–
library(rjson)

# You can pass directly the filename
my.JSON <- fromJSON(file=”c:/xyu_docs/Projects/Claims/testdata.json”)

##$df <- lapply(my.JSON, function(play) # Loop through each “play”
##$ {
# Convert each group to a data frame.
# This assumes you have 6 elements each time
##$ data.frame(matrix(unlist(play), ncol=21, byrow=T))
##$ })
data.frame(ncol=21, byrow=T)

# Now you have a list of data frames, connect them together in
# one single dataframe
df <- do.call(rbind, df)

# Make column names nicer, remove row names
colnames(df) <- names(my.JSON[[1]][[1]])
rownames(df) <- NULL
View(df)

Leave a Reply

Your email address will not be published. Required fields are marked *