How to deal with Error in fromJSON("transcripts_ru_2023-01-16.json") : not all data was parsed (0 chars were parsed out of a total of 30 chars)?

huangapple go评论120阅读模式
英文:

How to deal with Error in fromJSON("transcripts_ru_2023-01-16.json") : not all data was parsed (0 chars were parsed out of a total of 30 chars)?

问题

我正在尝试在R中加载一个JSON文件,但我不断收到以下错误:

Error in fromJSON("transcripts_ru_2023-01-16.json") : 
  not all data was parsed (0 chars were parsed out of a total of 30 chars)

这是我正在使用的代码:

install.packages("rjson")

library("rjson")

data <- fromJSON("transcripts_ru_2023-01-16.json")

数据可在此处获取:https://drive.google.com/file/d/1MeKgd2hyicXjuZH1JnhFxNyFwpBXaFoj/view?usp=sharing

英文:

I am trying to load a JSON file in R, but I keep receiving the following error:

Error in fromJSON(&quot;transcripts_ru_2023-01-16.json&quot;) : 
  not all data was parsed (0 chars were parsed out of a total of 30 chars)

Here is the code I am using:

install.packages(&quot;rjson&quot;)

library(&quot;rjson&quot;)

data &lt;- fromJSON(&quot;transcripts_ru_2023-01-16.json&quot;)

Data available here: https://drive.google.com/file/d/1MeKgd2hyicXjuZH1JnhFxNyFwpBXaFoj/view?usp=sharing

答案1

得分: 1

这是一个以换行符分隔的 JSON 数据;每行都是一个独立的 JSON 对象。
由于数据相对较小,你可以使用类似下面的方式将其全部加载到内存中:

tscr <- jsonlite::stream_in(file("transcripts_en_2023-01-16.json"))

将其转换为 tibble 格式:

tibble::as_tibble(tscr)

创建日期:2023-07-17,使用 reprex v2.0.2 工具生成。

英文:

It's a newline-delimited JSON; each individual line is a separate JSON object.
As it's quite small for what it is, you can probably load it all to memory with something like this:

tscr &lt;- jsonlite::stream_in(file(&quot;transcripts_en_2023-01-16.json&quot;))
#&gt; opening file input connection.
#&gt;  Found 500 records... /.../ Imported 9349 records. Simplifying...
#&gt; closing file input connection.

tibble::as_tibble(tscr)
#&gt; # A tibble: 9,349 &#215; 10
#&gt;    date        persons transcript_unfiltered kremlin_id place title teaser tags 
#&gt;    &lt;chr&gt;       &lt;list&gt;  &lt;chr&gt;                      &lt;int&gt; &lt;chr&gt; &lt;chr&gt; &lt;chr&gt;  &lt;lis&gt;
#&gt;  1 1999-12-31… &lt;list&gt;  Vladimir Putin: Dear…      22280 &quot;The… New … &quot;&quot;     &lt;chr&gt;
#&gt;  2 1999-12-31… &lt;list&gt;  Vladimir Putin: Good…      22326 &quot;The… Addr… &quot;&quot;     &lt;chr&gt;
#&gt;  3 1999-12-31… &lt;list&gt;  Boris Yeltsin: Dear …      24080 &quot;The… Stat… &quot;&quot;     &lt;chr&gt;
#&gt;  4 2000-01-04… &lt;list&gt;  Question: Mr Putin, …      24377 &quot;Mos… Inte… &quot;&quot;     &lt;chr&gt;
#&gt;  5 2000-01-11… &lt;list&gt;  Vladimir Putin: Dear…      24116 &quot;Sta… Spee… &quot;&quot;     &lt;chr&gt;
#&gt;  6 2000-01-15… &lt;list&gt;  Sergei Dorenko: Mr. …      24123 &quot;&quot;    Inte… &quot;&quot;     &lt;chr&gt;
#&gt;  7 2000-01-18… &lt;list&gt;  Question: You have s…      24125 &quot;Mos… Conv… &quot;&quot;     &lt;chr&gt;
#&gt;  8 2000-01-18… &lt;list&gt;  Vladimir Putin: I am…      24124 &quot;Mos… A sp… &quot;&quot;     &lt;chr&gt;
#&gt;  9 2000-01-21… &lt;list&gt;  Vladimir Putin: Dist…      21505 &quot;Mos… Open… &quot;&quot;     &lt;chr&gt;
#&gt; 10 2000-01-23… &lt;list&gt;  Nikolai Svanidze: Th…      24126 &quot;&quot;    Inte… &quot;&quot;     &lt;chr&gt;
#&gt; # ℹ 9,339 more rows
#&gt; # ℹ 2 more variables: transcript_filtered &lt;chr&gt;, wordlist &lt;list&gt;

<sup>Created on 2023-07-17 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年7月18日 02:34:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定