RJSONIO icon indicating copy to clipboard operation
RJSONIO copied to clipboard

convert json to datatable using rjsonio

Open simran-k opened this issue 8 years ago • 1 comments

I have properly formatted JSON fetched through a standard API.

API Basically returns an array of JSON objects each time I fetch data.

LIke this:

[ {}, {}, {} ]

I have used JSON editor to check structure of JSON data and that looks perfect. I need to convert it to CSV so tried this:

freshDeskRaw <- fromJSON(freshDeskTickets)
tmp <- lapply(freshDeskRaw , function(u) 
  lapply(u, function(x) if(is.null(x)) NA else x)
)
tmp <- lapply( tmp, as.data.frame)
tmp <- do.call( rbind, tmp )

At

tmp <- lapply( tmp, as.data.frame), I get an error:

> tmp <- lapply( tmp, as.data.frame)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 0, 1

how do I fix this? what looks wrong? I have tried to use

as.data.frame(tmp) as well but still get the same error.

simran-k avatar Sep 06 '16 11:09 simran-k

We have no idea what the result of freshDeskRaw is or what the JSON text contains!

duncantl avatar Sep 06 '16 13:09 duncantl