StructMapping.jl

Mapping a nested Dict to struct in Julia
Author matsueushi
Popularity
7 Stars
Updated Last
8 Months Ago
Started In
September 2020

StructMapping.jl

This package allows to map a nested Dict to struct.

julia> using Parameters, StructMapping

julia> @with_kw struct A
           a::Float64
           b::String
       end

julia> @with_kw struct B
           a::A
           b::Int64
       end

julia> j = Dict("a"=>Dict("a"=>1.0, "b"=>"hello"), "b"=>2)
Dict{String,Any} with 2 entries:
  "b" => 2
  "a" => Dict{String,Any}("b"=>"hello","a"=>1.0)

julia> b = convertdict(B, j)
B
  a: A
  b: Int64 2

julia> b.a
A
  a: Float64 1.0
  b: String "hello"

Documentation

Related packages