Problem reading JSON file

Hi,

I'm trying to read my JSON file in R but I get this error. Before it worked always and now all of a sudden I have this message and I can't access the file.

index_json <- jsonlite::read_json("01-assignment/Data/724500973ODKK3IFQ447-2021-12-31-en.json")
Error in open.connection(con, "rb") : cannot open the connection

It says open.connection but the file is locally saved on my computer.

Could anyone please help me resolve this error?

Hello @Juliavv ,

I am assuming that you did not make a typo in the name (e.g. by changing 0 in O or vice versa) ??

In my system (Windows) local files have absolute names as D:\data\R\myfolder\myfile.json
so starting with a drive-letter.
The name you use suggests that the file is somewhere in a project folder,
so that you could work with a relative name.
If your 01-assignment folder is a (direct) subfolder in your project folder you could use the name

"./01-assignment/Data/724500973ODKK3IFQ447-2021-12-31-en.json"

If this does not help, let us know your folder structure.

@HanOostdijk
Thank you for your response, I tried it with the dot but it still doesn't work. I set my working directory until the assignments tab, and then I have these sub tabs like the 01-assignment. So this is where I should start.

As you describe it, it should work with and without adding ./ to the filename.

With the current directory set as you told us two questions:

do you see the directory 01-assignment/Data/ in the output of

list.dirs()

and do you see the json file in the output of

list.files(path="01-assignment/Data/") 

??

When I put list.dirs() I get my output as /Data/..

And when I do the same in Assignment 2 it still works, so I thing it is solved when i remove the 01-assignment part. Thanks for your help!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.