# JSON.parsefile() returning load error Unexpected Character

**URL:** <https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 13, 2020, 7:40pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338 "2020-06-13T19:40:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![waqas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waqas/32/15176_2.png) [@waqas](https://discourse.julialang.org/u/waqas)\
**Post date:** [June 13, 2020, 7:40pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/1 "2020-06-13T19:40:02Z")

</div>

Hi,

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:

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

download("https://raw.githubusercontent.com/ageron/handson-ml/master/datasets/housing/housing.csv","newhouses.csv")
houses= CSV.read("newhouses.csv")
download("https://github.com/JuliaAcademy/DataScience/blob/master/data/california-counties.json","california-counties.json")
cali_shape = JSON.parsefile("california-counties.json")

```

```julia
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

```

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [June 13, 2020, 7:51pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/2 "2020-06-13T19:51:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waqas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waqas/32/15176_2.png) [@waqas](https://discourse.julialang.org/u/waqas)\
**Post date:** [June 13, 2020, 8:54pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/3 "2020-06-13T20:54:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [June 13, 2020, 11:19pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/4 "2020-06-13T23:19:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![waqas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waqas/32/15176_2.png) [@waqas](https://discourse.julialang.org/u/waqas)\
**Post date:** [June 14, 2020, 6:16am UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/5 "2020-06-14T06:16:51Z")

</div>

So am I downloading html file from [https://github.com/JuliaAcademy/DataScience/blob/master/data/california-counties.json](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.

```julia
download("https://github.com/JuliaAcademy/DataScience/blob/master/data/california-counties.json","california-counties.json")

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

```

---

<div class="post-metadata">

**Author:** ![waqas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waqas/32/15176_2.png) [@waqas](https://discourse.julialang.org/u/waqas)\
**Post date:** [June 14, 2020, 6:31am UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/6 "2020-06-14T06:31:27Z")

</div>

> [@waqas](#):
>
> I have been using same commands when I was downloading from csv file from github.

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.

Cheers,

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [June 14, 2020, 3:26pm UTC](https://discourse.julialang.org/t/json-parsefile-returning-load-error-unexpected-character/41338/7 "2020-06-14T15:26:15Z")

</div>

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:

[https://raw.githubusercontent.com/JuliaAcademy/DataScience/master/data/california-counties.json](https://raw.githubusercontent.com/JuliaAcademy/DataScience/master/data/california-counties.json)
