How To Parse JSON in R Without "Losing" Empty Elements -
I am trying to parse JSON which is coming to me as an array of array (seems That's a table of data). The point is that in this table, there are elements in the form of arrays or maps and these elements can be emptied. Here's an example:
json & lt; There is a list of # 2 results where 'each sublist' - [[1, "foo", [], {}], [1, "bar", [1], {"foo": "bar"} Length is 4 jsonlite :: fromJSON (json) #The result is a character vector of length 6 & gt; Unknowingly (JSNLET :: JSON (JSSN)) [1] "1" "FU" "1" "Bar" "1" "Bar" So when I try it Insert 2 to 4 matrix, I get the wrong answer. I would like to map [] from "[]" and {} to "{}" So I do not lose the elements, instead of parsing it as a list, it's completely okay to return the nested array as "[1]" I feel like I have a Jason's Parser Need to stop remembering and treat the elements at a certain point, but I can not understand how to do it I am not tied to the jsonlite package, so basically nothing is not a proper game, because it is not slow.
You can repeat the parsed Jason to find empty lists and for those values You can replace them with the ones you want. For example
renameEmptyLists & lt; {Function (x) {if (is.list (x)} {if (length (x) == 0} {return (if!! Is.null (name (x)) {"{}"} { "[]"})} Other {returns (sloping (X, named name empty list)}} and {x}} JJ & LT; To be more clear, you unlist () -> JasonLight :: Eugene Jason) "" "1" "bar" "1" / Code> If you look at the jj object in my example, you will see that the pars has identified the correct list and empty named list.
Comments
Post a Comment