Elektra
0.9.4
|
This is a plugin reading and writing JSON files using the library yail
The plugin was tested with yajl version 1.0.8-1 from Debian 6 and yajl version 2.0.4-2 from Debian 7.
Examples of files which are used for testing can be found below the folder in "src/plugins/yajl/yajl".
The JSON grammar can be found here.
A validator can be found here.
Supports every KeySet except when arrays are intermixed with other keys. Has only limited support for metadata.
libyajl-dev
(version 1 and 2 should work)The type of the data is available via the metadata type
:
string
: The JSON string type.boolean
: The JSON boolean type (true or false)double
: For JSON numbers.If no metadata type
is given, the type is either:
null
on binary null-keystring
otherwiseAny other type/value will still be treated as string, but the warning C03200
will be added because of the potential data loss.
In JSON it is possible to have empty arrays and objects. In Elektra this is mapped using the special names
and
Arrays are mapped to Elektra’s array convention #0, #1,..
iconv
plugin if your locale are not UTF-8. When using non-UTF-8 the plugin will be able to write the file, but cannot parse it back again. You will error C03100, invalid bytes in UTF8 string.Because of these potential problems a type checker and comments filter are highly recommended.
The following example shows you how you can read and write data using this plugin.
`` @section autotoc_md783 Mount the plugin to the cascading namespace
/tests/yajl` sudo kdb mount config.json /tests/yajl yajl
printf '{ "number": 1337 }' > kdb file /tests/yajl
kdb get /tests/yajl/number #> 1337
kdb meta-get /tests/yajl/number type #> double
kdb set /tests/yajl/key value
kdb get /tests/yajl/key #> value
kdb file /tests/yajl/ | xargs cat #> { #> "key": "value", #> "number": 1337 #> }
kdb set /tests/yajl/piggy/#0 straw kdb set /tests/yajl/piggy/#1 sticks kdb set /tests/yajl/piggy/#2 bricks
kdb get /tests/yajl/piggy/#2 #> bricks
kdb file /tests/yajl | xargs cat #> { #> "key": "value", #> "number": 1337, #> "piggy": [ #> "straw", #> "sticks", #> "bricks" #> ] #> }
kdb rm -r /tests/yajl sudo kdb umount /tests/yajl
sudo kdb mount config.json user:/tests/yajl yajl
kdb set user:/tests/yajl/roots 'Things Fall Apart' kdb set user:/tests/yajl/roots/bloody 'Radical Face' kdb set user:/tests/yajl/roots/bloody/roots 'No Roots'
kdb set user:/tests/yajl/now ', Now'
kdb meta-set user:/tests/yajl/now array '' kdb set user:/tests/yajl/now/#0 'Neighbors' kdb set user:/tests/yajl/now/#1 'Threads'
kdb ls user:/tests/yajl #> user:/tests/yajl/now #> user:/tests/yajl/now/#0 #> user:/tests/yajl/now/#1 #> user:/tests/yajl/roots #> user:/tests/yajl/roots/bloody #> user:/tests/yajl/roots/bloody/roots
kdb get user:/tests/yajl/roots #> Things Fall Apart kdb get user:/tests/yajl/roots/bloody #> Radical Face
kdb get user:/tests/yajl/roots/bloody/roots #> No Roots
kdb get user:/tests/yajl/now #> , Now kdb meta-get user:/tests/yajl/now array #> #1 kdb get user:/tests/yajl/now/#0 #> Neighbors kdb get user:/tests/yajl/now/#1 #> Threads
kdb rm -r user:/tests/yajl sudo kdb umount user:/tests/yajl
kdb mount conf.json user:/tests/yajl yajl kdb set user:/tests/yajl 1 kdb get user:/tests/yajl #> 1 kdb meta-set user:/tests/yajl type boolean kdb set user:/tests/yajl on kdb get user:/tests/yajl #> 1 kdb set user:/tests/yajl/subkey disable kdb meta-set user:/tests/yajl/subkey type boolean kdb get user:/tests/yajl/subkey #> 0
kdb rm -r user:/tests/yajl sudo kdb umount user:/tests/yajl
or:
Then you can copy the OpenICC_device_config_DB.json
to systemwide or user config, e.g.
prints out then all device entries available in the config
prints out "Glasshuette" with the example config in source
You can export the whole system openicc config to ini with:
or import it: