0

I have a large (210 038 KB) txt file which contains json structured data. It contains itinerary data, which I would like to structure the data on a journey basis, which should be easy enough as long as I can find where in the nesting this is located. My main challenge is that I don't know the structure of the data, and when I try to read it in R with for instance read.table('datafile.txt', header=FALSE) it either runs for a very long time and then crashes, alternatively it produced an unsatisfactory result by separating on "wrong" character (and then it had to restart itself).

I've glanced this post: Parsing JSON arrays from a .txt file in R - several large files which is similar to mine, but there the data were separated by newlines. I instead need to iteratively read the json structure and find out what it's comprised of.

Any suggestions?

OLGJ
  • 331
  • 1
  • 7
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 15 '23 at 14:52
  • I would do that if I could. But maybe my request was a bit diffuse, what I would like to do is first read the txt file, then be able to iteratively work my way down the nested structure by viewing what's in the file. In python I do this with `import json with open('ETHistory2023-02-15.txt') as f: json_data = json.load(f)` and then for instance `json_data.keys()` and continue my way down with `json_data['key1']` and so forth. I'm looking to do take the same approach here but using R instead. – OLGJ Feb 16 '23 at 08:10
  • In R you would use something like `jsonlite::read_json` to read the data into a list. Then you use `names()` to get named objects in the list rather than `.keys()`. And when you go deeper, just make sure to use double braces `json_data[['key1']]` in R. – MrFlick Feb 16 '23 at 15:34

0 Answers0