JSON.parsefile() returning load error Unexpected Character


I am trying to follow the tutorials on “Julia for Data science” and am getting Unexpected Character error whenever I try to use JSON.parsefile(). I have tried many different JSON files but, the error still pops up. I found a somewhat similar problem in another thread but author of that had later on developed LazyJSON. I tried that too along with JSON2.jl and JSON3.jl but no success.

Can someone please recommend something regarding this? Code and error are posted below:

using Clustering 
using VegaLite
using VegaDatasets
using DataFrames
using Statistics
using JSON
using CSV
using Distances

houses= CSV.read("newhouses.csv")
cali_shape = JSON.parsefile("california-counties.json")
LoadError: Unexpected character
Line: 5
Around: ...     <!DOCTYPE html> <html ...
in expression starting at Z:\Julia Tutorials\tutorial_5.jl:15
error(::String) at error.jl:33
_error(::String, ::JSON.Parser.MemoryParserState) at Parser.jl:142
parse_jsconstant(::JSON.Parser.ParserContext{Dict{String,Any},Int64,true,nothing}, ::JSON.Parser.MemoryParserState) at Parser.jl:195
parse_value(::JSON.Parser.ParserContext{Dict{String,Any},Int64,true,nothing}, ::JSON.Parser.MemoryParserState) at Parser.jl:172
parse(::String; dicttype::Type{T} where T, inttype::Type{Int64}, allownan::Bool, null::Nothing) at Parser.jl:463
(::JSON.Parser.var"#parse##kw")(::NamedTuple{(:dicttype, :inttype, :allownan, :null),Tuple{DataType,DataType,Bool,Nothing}}, ::typeof(JSON.Parser.parse), ::String) at Parser.jl:461
#4 at Parser.jl:524 [inlined]
open(::JSON.Parser.var"#4#5"{DataType,DataType,Nothing,Bool,Bool,Int64}, ::String; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at io.jl:298
open at io.jl:296 [inlined]
#parsefile#3 at Parser.jl:522 [inlined]
parsefile(::String) at Parser.jl:521
top-level scope at tutorial_5.jl:15

That appears to be a XML file not a JSON file…

To be honest, I do not have much experience in any of the formats. Atleast the instructor in the course was using JSON without an issue. So I am basically looking for the solution.

That is an html file…so I’m not sure what you want to do with it…

So am I downloading html file from https://github.com/JuliaAcademy/DataScience/blob/master/data/california-counties.json?

I have been using same commands when I was downloading from csv file from github.


cali_shape = JSON.parsefile("california-counties.json")
1 Like

Just realized my mistake. I am saving html page rather than downloading .json file. Hopefully I will download the required file now. You can reply the correction in download() function and I will mark that as answer.


For github there is usually a “raw” button that you can download the file directly. Otherwise github wraps it in a pretty display…So the URL you probably want is: