Write StatsBase Histogram to JSON using JSON3

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

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


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

But I keep getting the error

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.

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.