API

Types

Functions and macros

Documentation

PropDicts.MissingPropertyType
struct MissingProperty

An instance MissingProperty(parent, key::Symbol) represents the fact the key is missing in parent.

Instances of MissingProperty support setindex! and setproperty!, this will create the key in parent as a PropDict.

source
PropDicts.PropDictType
PropDict <: AbstractDict{Union{Symbol,Int},Any}

PropDicts is a dictionary for that supports

Constructors:

PropDict(dict::AbstractDict)

PropDict(key1 => value, key2 => value2, ...)

During construction, keys are automatically converted to Symbols and Ints, values that are dicts are converted to PropDicts.

PropDict support deep merging:

x = PropDict(:a => PropDict(:b => 7, :c => 5, :d => 2), :e => "foo")
y = PropDict(:a => PropDict(:c => 42, :d => nothing), :f => "bar")

z = merge(x, y)
@assert z == PropDict(
    :a => PropDict(:b=>7, :d => nothing, :c => 42),
    :e => "foo", :f => "bar"
)

PropDicts.trim_null!(z)
@assert z == PropDict(
    :a => PropDict(:b=>7, :c => 42),
    :e => "foo", :f => "bar"
)

Acessing non-existing properties will return instances of PropDicts.MissingProperty). When setting the value of missing properties, parent PropDicts are created automatically:

z.foo.bar isa PropDicts.MissingProperty
z.foo.bar = 42
z.foo.bar == 42

PropDicts can be read/written to/from JSON and YAML files using readprops and writeprops. Note that the Julia packages JSON resp. YAML need to be loaded first.

Note

Like with Base.Dict, mutating a PropDict is not thread safe.

source
PropDicts.readpropsFunction
readprops(filename::AbstractString; subst_pathvar::Bool = true, subst_env::Bool = true, trim_null::Bool = true)
readprops(filenames::Vector{<:AbstractString}; ...)

Read a PropDict from a single or multiple files.

readprops supports JSON and YAML files. Note that the Julia packages JSON resp. YAML need to be loaded first.

If multiple files are given, they are merged into a single PropDict using merge.

subst_pathvar controls whether $_ should be substituted with the directory path of the/each file within string values (but not field names).

subst_env controls whether $ENVVAR should be substituted with the value of the each environment variable ENVVAR within string values (but not field names).

trim_null controls whether JSON/YAML null values should be removed entirely.

source
PropDicts.trim_null!Function
trim_null!(d::AbstractDict; recursive::Bool = true)

Remove values equal to nothing from d.

Operates recursively on values in d if recursive == true.

source
PropDicts.writepropsFunction
writeprops(io::IO, p::PropDict; multiline::Bool = true, indent::Int = -1)
writeprops(filename, p::PropDict; format = :JSON, multiline::Bool = true, indent::Int = -1)

Write PropDict p to JSON file filename.

writeprops supports JSON and YAML files. Note that the Julia packages JSON resp. YAML need to be loaded first.

multiline = false is not supported for YAML files.

Use indent = -1 for default indentation in multiline mode.

source