libelektra: YAJL: Invalid JSON Sequence
A key creation sequence involving a object followed by a array creates invalid json.
Steps to Reproduce the Problem
kdb set /org/freedesktop/openicc/one/key val
#> Using name user/org/freedesktop/openicc/one/key
#> Create a new key user/org/freedesktop/openicc/one/key with string "val"
kdb set /org/freedesktop/openicc/#1/key other
#> Using name user/org/freedesktop/openicc/#1/key
#> Create a new key user/org/freedesktop/openicc/#1/key with string "other"
kdb ls /org/freedesktop/openicc
#> The command kdb ls failed while accessing the key database with the info:
#> Sorry, the error (#77) occurred ;(
#> Description: Yajl parser error
#> Reason: parse error: after array element, I expect ',' or ']'
#> } } } } }
#> (right here) ------^
#>
#> Ingroup: plugin
#> Module: yajl
#> At: /tmp/libelektra/src/plugins/yajl/yajl_parse.c:381
#> Mountpoint: user/org/freedesktop/openicc
#> Configfile: ~/.config/color/settings/openicc.json
Expected Result
Return just an error for the array index on a object path. Or use the #1 index to access a existing object, but do not create a array if a a object is already in place.
Actual Result
The below JSON contains a opening array ‘[’ without closing ‘]’.
{
"org": {
"freedesktop": {
"openicc": [
{
"key": "other",
"key": "val"
}
}
}
}
}
System Information
- Elektra Version: master
- yajl-2.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (14 by maintainers)
Commits related to this issue
- doc: document JSON correction see #1862 — committed to ElektraInitiative/libelektra by deleted user 6 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
- YAML CPP: Support maps containing array keys See also: [Issue #1862](https://issues.libelektra.org/1862) — committed to sanssecours/elektra by sanssecours 5 years ago
Oh, the sequence was only a example. No need to name a key “key” from my side
should be enough 😄
I added
key, because it was part of the initial issue description.Yep, that simpler JSON object also shows how to handle the issue.
None of the YAML plugins handle this situation (in the
setdirection) properly. In my opinion the best solution to solve this problem is to just use a map containing the keys#1andone.. In the
getdirection this already works in YAML CPP, Yan LR, YAMBi, YAwn and YAy PEG:. The same strategy should also work for YAJL. The JSON version of the YAML file above looks like this:
. Unfortunately YAJL does not handle this situation in the
getdirection properly:.
Nope. I think this problem should be fixed inside YAJL and not in the Directory Value plugin.
Indeed it works:
It is only a low level JSON editor for scripting, API design and testing.
Correct. However arrays are quite practical and can be used reasonably. JSON is a serialisation syntax. So I am still optimistic and guess most users will not shuffle keys or arrays.