【发布时间】:2016-05-03 04:27:24
【问题描述】:
对于我的博士项目,我需要将 JSONL 文件读入 R(扩展名不是 json,是 jsonl)并将其转换为 csv。 我尝试使用基于 jsonlite 的代码,但它给了我一个错误:
library(jsonlite)
data <- "/Users/chiarap/tweets.jsonl"
dat <- fromJSON(sprintf("[%s]", paste(readLines(data), collapse=",")))
Error: parse error: unallowed token at this point in JSON text
EFEF","notifications":null}},,,{"in_reply_to_status_id_str":
(right here) ------^
谢谢
【问题讨论】:
-
我第一次听说
jsonl,但我想这只是标准的json,其中每一行都是不同的json。尝试为文件的每一行调用fromJSON。例如content<-readLines(data),然后是fromJSON(content[i]),其中i介于1 和文件中的行数之间。 -
@nicola 非常感谢你,它有效。在写到这里之前,我尝试使用结合 fromJSON 的 readLines 函数,但我找不到任何如何正确编写脚本的示例。这很有帮助。