API
Types
Functions and macros
Documentation
PropDicts.MissingProperty
— Typestruct 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
.
PropDicts.PropDict
— TypePropDict <: 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 Symbol
s and Int
s, values that are dicts are converted to PropDict
s.
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 PropDict
s are created automatically:
z.foo.bar isa PropDicts.MissingProperty
z.foo.bar = 42
z.foo.bar == 42
PropDict
s can be read/written to/from JSON files using readprops
and writeprops
.
Like with Base.Dict
, mutating a PropDict
is not thread safe.
PropDicts.readprops
— Functionreadprops(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 JSON files.
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 JSON 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 null
values should be removed entirely.
PropDicts.trim_null!
— Functiontrim_null!(d::AbstractDict; recursive::Bool = true)
Remove values equal to nothing
from d
.
Operates recursively on values in d
if recursive == true
.
PropDicts.writeprops
— Functionwriteprops(filename, p::PropDict; multiline::Bool = false, indent::Int = 4)
Write PropDict
p
to JSON file filename
.