1

For a project I'd like to read a JSON file of 9.3 MB into R and use it as a dataframe. The JSON looks as following:

{"id":"xxx"}
{"id":"xxx"}
{"id":"xxx"}
{"id":"xxx"}
.
.
.

With the following function

dh <- fromJSON(paste(readLines(json_file), collapse = ""))

I was able to import it, within my environment it is however shown as a "Large Character (9.3)" and I'm not able to further use it.

Notes

Could the handling of the file in said way have anything to do with its size?

First time working with JSON files, please go easy on me.

Thanks for any input that might help/help me get some clarity regarding working with JSON in R.

5
  • I think that might be because your json file is just full of just ids. What you can try maybe is :- dh <- as.data.frame(fromJSON(paste(readLines(json_file), collapse = ""))) Commented Aug 6, 2021 at 7:50
  • Thank you, unfortunately this just produces 1 obs. of 1 variable in my code ... Commented Aug 6, 2021 at 7:58
  • Can you provide a link to the file? Commented Aug 6, 2021 at 8:09
  • What about paste0("[", paste0(readLines(json_file), collapse = ","), "]") ? Commented Aug 6, 2021 at 9:10
  • No, unfortunately not. It is an exported file from a certain platform in work, that's the reason why I substituted the ID's and naming convention Commented Aug 6, 2021 at 9:10

1 Answer 1

2
> fromJSON(paste0("[", paste0(readLines(json_file), collapse = ","), "]"))
   id
1 xxx
2 xxx
3 xxx
4 xxx
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.