0

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.

systemdebt
  • 4,589
  • 10
  • 55
  • 116

1 Answers1

0

The problem might be that the JSON above produces empty lists and

is.null(list())
# [1] FALSE

Try

is.null(x) || (is.list(x) && length(x) == 0)
Jan Kislinger
  • 1,441
  • 14
  • 26