Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error in fromJSON("employee.json") : not all data was parsed (0 chars were parsed out of a total of 13 chars)

I was trying to read the JSON file from my r studio as a purpose of learning how to read JSON file, but suddenly i got an parsing error.


employee.json

{   
   "id" : ["1","2","3","4","5","6","7","8" ],  
   "name" : ["Shubham","Nishka","Gunjan","Sumit","Arpita","Vaishali","Anisha","Ginni" ],  
   "salary" : ["623","552","669","825","762","882","783","964"],  
   "start_date" : [ "1/1/2012","9/15/2013","11/23/2013","5/11/2014","3/27/2015","5/21/2013","7/30/2013","6/17/2014"],  
   "dept" : [ "IT","Operations","Finance","HR","Finance","IT","Operations","Finance"]  
}  

.R file

library(rjson)
emp = fromJSON("employee.json")
e = as.data.frame(emp)
print(e)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The first argument to rjson::fromJSON is a JSON string. So your code is interpreting "employee.json" (note it has 13 characters) as JSON.

If you have saved a file named employee.json, you need to specify file = :

rjson::fromJSON(file = "employee.json")

This is not an issue when using jsonlite::fromJSON because the first argument can be a string, file or URL.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading