New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
YAJL: Plugin Adds Empty Parent Key #2132
Comments
Thank you for reporting the bug! |
I think when issue #2129 is resolved I can look into this next. |
Thank you, I assigned you! |
I tried to get an understanding of what's going on. So with the above mentioned
With YamlCPP on the other hand, The files look semantically the same, that is |
While filtering should work, I think it would be better to not create any intermediate keys in the first place. For example, if we mount the following file: {
"level1": {
"level2": {
"level3": "something"
}
}
} at the namespace
.
I guess so too, but that sounds like a workaround to me. It would probably be enough to fix the problem described in this issue though. |
That sounds like a better idea. However from looking at the parsing code, I'm not sure whether this is possible. When parsing So I created a pull request #2580 which filters the empty keys out, after parsing is done. Looking forward to feedback. |
That might be the case. I do not know the YAJL plugin code at all. Since YAML CPP, Yan LR, YAMBi, YAwn, and Yay PEG do not add any intermediate keys, my guess would be that it should be possible.
I assume the interface of YAJL is very similar to the one of an ANTLR listener class, meaning that the parser calls specific functions, if it notices a certain element in the JSON file, such as a map or a string. In that case, I think you can handle this situation with code that is similar to Yan LRβs listener class. What Yan LR basically does is keep a temporary stack of keys (
. Every time the plugin leaves a key-value pair it drops the last key in the {
"level1": {
"level2": {
"level3": "something"
}
},
"one": {
"two": "three"
}
} at # Stack
user/parent . Then the plugin parses the JSON file and finds a key-value pair containing the key # Stack
user/parent
user/parent/level1 . Please note, that I reversed the stack (it grows downwards), since in this notation the stack looks more similar to the JSON data. In the next step YAJL finds another dictionary containing a key-value pair with # Stack
user/parent
user/parent/level1
user/parent/level1/level2 . The next step looks similar, since YAJL finds another key-value pair, this time with the key # Stack
user/parent
user/parent/level1
user/parent/level1/level2
user/parent/level1/level2/level3 . Then the plugin finds the first non-dictionary value ( # Key Set
user/parent/level1/level2/level3: something . In the next step YAJL leaves the key-value pair # Stack
user/parent
user/parent/level1
user/parent/level1/level2 . After that a # Stack
user/parent
user/parent/level1 . Another closing brace in the next line shows that it is time to drop another element from the stack: # Stack
user/parent . Afterwards YAJL finds another key-value pair that contains the key
. YAJL then finds the last key-value pair
. The non-dictionary value
. Afterwards YAJL leaves two key-value pairs, which means it is time to drop two elements from the stack:
. At the end of the document YAJL destroys the whole stack and returns the final key set: user/parent/level1/level2/level3: something
user/parent/one/two: three . I hope the explanation above helps. Just as I said before: I do not know, if the whole procedure is applicable to YAJL, but I would at least assume that something similar should be possible. |
Thank you, very clear explanation! But yajl does not use a stack for parsing and instead immediately adds keys to the KeySet and lets the internal cursor point to that element. That doesn't necessarily rule out the possibility of doing that. In your example, each time a libelektra/src/plugins/yajl/yajl_parse.c Lines 188 to 215 in 072db3d
For instance, with this json
the log (shortened) looks like this
So it seems But when the parser hits the map key I'm thinking about changing the parser to adding a basename instead of overwriting it, but I'll have to look into this more later. For now anyway, I think with the current parser its not possible to easily drop the unneeded keys. |
- Remove directoryvalue plugin as a yajl dependency until this is fully implemented - Issue: ElektraInitiative#2132
Is this now done? @PhilippGackstatter Will you continue working on that? |
No, PR #2580 has fixed this issue. After fixing it, I thought I'd found a better way, but it was a dead end. |
Thank you for the fast response! |
Steps to Reproduce the Problem
Expected Result
The last command should print the following output:
. At least YAML CPP handles this situation correctly:
.
Actual Result
The command
kdb ls user/tests/yajl
prints the following output:.
System Information
The text was updated successfully, but these errors were encountered: