Json Schedule Files

103 views
Skip to first unread message

Joseph English

unread,
Oct 12, 2022, 5:47:37 AM10/12/22
to A gathering place for the Open Rail Data community
Hi All,

Beginner here, I have been struggling the past few weeks with how to interact and format the network rail schedule files, which I have been trying to use as Json format in python. How can I unzip the .gz and if possible, how can I format it into a database that I can query using SQL and Python?

Thanks,

Joe

Ian Sargent

unread,
Oct 12, 2022, 5:56:16 AM10/12/22
to A gathering place for the Open Rail Data community
You should be able to unpack the "gz" file with most of the common zip/unzip utilities.

Joseph English

unread,
Oct 12, 2022, 6:42:25 AM10/12/22
to A gathering place for the Open Rail Data community
Have unpacked the file and renamed it as .json, however python doesn't seem to like that and gives this error


f = open('toc-full.json')

data = json.load(f)

print(f)


Traceback (most recent call last):
  File "/Users/josephenglish/OneDrive/CS NEA SAM VERSION/Schedule_SQL/main.py", line 9, in <module>
    data = json.load(f)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 220)

Peter Hicks

unread,
Oct 12, 2022, 8:06:14 AM10/12/22
to A gathering place for the Open Rail Data community
Hi Joe

It's one record per line - so rather than trying to parse it all as one blob of JSON, read in a line and parse it, etc.


Peter

--
You received this message because you are subscribed to the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openraildata-t...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openraildata-talk/b106d6d5-bc87-4728-a51c-d43852158057n%40googlegroups.com.

Douglas Fraser

unread,
Oct 13, 2022, 3:59:14 PM10/13/22
to openrail...@googlegroups.com
Hi Joe,

I would suggest looking into the command-line utility jq.  It is very useful for dealing with json and will handle the multiple JSON objects in a file, one per line, format


Doug


Reply all
Reply to author
Forward
0 new messages