A problem with parsing JSON files located at a specific address

If you look at the help for JSON.parse it has two forms:

Parses the given JSON string into corresponding Julia types

and:

Parses JSON from the given IO stream into corresponding Julia types.

Neither of those open a file and read the contents. Which would be an issue anyway since the file isn’t a single JSON object, but mutliple.

An easy solution for you (assuming NONE or your JSON objects have a \n in them) is to do:

loaded = read("C:/Users/me/data/1.122431815", String)
for object in split(loaded, "\n")
    json = JSON.parse(object)
end

The first line will load whole file as a string. split() will break the file into multiple lines, so a JSON object must be on a single line in the file. Then JSON.parse() can decode a single JSON object.

1 Like