Is there a way other than below to load a json.rows file into RStudio?

五迷三道 提交于 2019-12-19 10:32:19

问题


I have a json.rows file -> instances.json.rows with approximately 223k rows

I tried using jsonlite and came up with

instancesfile <- fromJSON("instances.json.rows")

But i kept getting an error

Error in parse_con(txt, bigint_as_char) : parse error: trailing garbage
      kcBy-cs", "time_type": "in"} {"cluster_ids": ["Bz4SOc6zZn0"]
                 (right here) ------^

Here is an image of the data from the first row of my file. Apologies if my question is not clear enough. Let me know in the comments and I will edit my question as required. Thank you in advance!


回答1:


out <- lapply(readLines("instances.json.rows"), fromJSON)

Congrats out is what you want it to be. The L apply applies the fromJSON function to each member returned from readLines and returns the results to out. I miss Spoke a bit in my comment, to make your file valid json you would have to replace the newlines with comma, then put the result where the * is in the below example. But that's all non-sense, just use the above one liner.

{"data":[*]}


来源:https://stackoverflow.com/questions/43302834/is-there-a-way-other-than-below-to-load-a-json-rows-file-into-rstudio

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!