I am trying to parse JSON that is coming to me in the form of an array of arrays (think a table of data). The issue is that this table may contain arrays or maps as elements and these elements may by empty. Here is an example:
json <- '[[1,"foo",[],{}],[1,"bar",[1],{"foo":"bar"}]]'
# Result is a list of 2 where each sublist is of length 4
jsonlite::fromJSON(json)
# Result is a character vector of length 6
> unname(unlist(jsonlite::fromJSON(json)))
[1] "1" "foo" "1" "bar" "1" "bar"
So when I try and cast this to a 2 by 4 matrix I am getting the wrong answer. I would like [] to map to the string "[]" and {} to "{}" so I don't lose elements. It is totally fine for me to return the nested array as "[1]" instead of parsing it as a list. To me this seems like I need to tell the json parser to stop recursing and treat the elements as characters at a certain point but I can't figure out how to do this. I'm not tied to the jsonlite package so basically anything is fair game as long as it is not slow.
{"foo":"bar"}). Frankly, unless all of yourobjects will be single elements (and you remove either the key or value), it does not make sense to try to map it to a matrix. You may need to consider pruning the whole structure before trying to create a matrix.