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评论151阅读模式
英文:

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文件,但我不断收到以下错误:

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

这是我正在使用的代码:

  1. install.packages("rjson")
  2. library("rjson")
  3. 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:

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

Here is the code I am using:

  1. install.packages(&quot;rjson&quot;)
  2. library(&quot;rjson&quot;)
  3. 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 对象。
由于数据相对较小,你可以使用类似下面的方式将其全部加载到内存中:

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

将其转换为 tibble 格式:

  1. 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:

  1. tscr &lt;- jsonlite::stream_in(file(&quot;transcripts_en_2023-01-16.json&quot;))
  2. #&gt; opening file input connection.
  3. #&gt; Found 500 records... /.../ Imported 9349 records. Simplifying...
  4. #&gt; closing file input connection.
  5. tibble::as_tibble(tscr)
  6. #&gt; # A tibble: 9,349 &#215; 10
  7. #&gt; date persons transcript_unfiltered kremlin_id place title teaser tags
  8. #&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;
  9. #&gt; 1 1999-12-31… &lt;list&gt; Vladimir Putin: Dear… 22280 &quot;The… New … &quot;&quot; &lt;chr&gt;
  10. #&gt; 2 1999-12-31… &lt;list&gt; Vladimir Putin: Good… 22326 &quot;The… Addr… &quot;&quot; &lt;chr&gt;
  11. #&gt; 3 1999-12-31… &lt;list&gt; Boris Yeltsin: Dear … 24080 &quot;The… Stat… &quot;&quot; &lt;chr&gt;
  12. #&gt; 4 2000-01-04… &lt;list&gt; Question: Mr Putin, … 24377 &quot;Mos… Inte… &quot;&quot; &lt;chr&gt;
  13. #&gt; 5 2000-01-11… &lt;list&gt; Vladimir Putin: Dear… 24116 &quot;Sta… Spee… &quot;&quot; &lt;chr&gt;
  14. #&gt; 6 2000-01-15… &lt;list&gt; Sergei Dorenko: Mr. … 24123 &quot;&quot; Inte… &quot;&quot; &lt;chr&gt;
  15. #&gt; 7 2000-01-18… &lt;list&gt; Question: You have s… 24125 &quot;Mos… Conv… &quot;&quot; &lt;chr&gt;
  16. #&gt; 8 2000-01-18… &lt;list&gt; Vladimir Putin: I am… 24124 &quot;Mos… A sp… &quot;&quot; &lt;chr&gt;
  17. #&gt; 9 2000-01-21… &lt;list&gt; Vladimir Putin: Dist… 21505 &quot;Mos… Open… &quot;&quot; &lt;chr&gt;
  18. #&gt; 10 2000-01-23… &lt;list&gt; Nikolai Svanidze: Th… 24126 &quot;&quot; Inte… &quot;&quot; &lt;chr&gt;
  19. #&gt; # ℹ 9,339 more rows
  20. #&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:

确定