# Write StatsBase Histogram to JSON using JSON3

**URL:** <https://discourse.julialang.org/t/write-statsbase-histogram-to-json-using-json3/67601>\
**Category:** New to Julia\
**Tags:** json3\
**Created:** [September 2, 2021, 8:46pm UTC](https://discourse.julialang.org/t/write-statsbase-histogram-to-json-using-json3/67601 "2021-09-02T20:46:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonm/32/27392_2.png) [@Jonm](https://discourse.julialang.org/u/Jonm)\
**Post date:** [September 2, 2021, 8:46pm UTC](https://discourse.julialang.org/t/write-statsbase-histogram-to-json-using-json3/67601/1 "2021-09-02T20:46:33Z")

</div>

With help from @quinnj, I thought I was getting the hang of writing structs to JSON using JSON3. I can’t seem to teach JSON3 to write the Histogram object from StatsBase.jl

I have tried to use

```julia
StructTypes.StructType(::Type{Histogram}) = StructTypes.Struct()

```

and

```julia
StructTypes.StructType(::Type{Histogram}) = StructTypes.CustomStruct()
SructTypes.lower(x::typeof(h)) = ....

```

But I keep getting the error

```julia
MethodError: no method matching keys(::Histogram{Float64, 1, Tuple{Vector{Float64}}})
Closest candidates are:
  keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at /Users/jonm/.julia/packages/Tables/E99hk/src/Tables.jl:181
  keys(::Union{HDF5.File, HDF5.Group}) at /Users/jonm/.julia/packages/HDF5/0iEnL/src/HDF5.jl:942
  keys(::Base.Iterators.Pairs) at iterators.jl:268
  ...

```

no matter what I do. What am I missing ?

I can use JSON3 to write out each field from (:edges, :weights, :closed, :isdensity) of Histogram. But I can’t get this working automatically.

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [September 7, 2021, 11:17pm UTC](https://discourse.julialang.org/t/write-statsbase-histogram-to-json-using-json3/67601/2 "2021-09-07T23:17:56Z")

</div>

Can you share more complete examples of the code you’re using and/or stacktraces you’re seeing? Unfortunately, it’s hard to tell exactly what’s goign on without more information. Feel free to post a full script and we can help debug what’s going on.
