Closed dj4ngo closed 2 years ago
Else it seem to work fine with standard use case:
$ echo '{"one": 1, "two": 2, "three": 3, "four": {"five": 5, "six": 6, "seven": {"eight": 8, "nine": 9}}}' | \
> niet . -d .four.six -d .four.seven.eight
{
"one": 1,
"two": 2,
"three": 3,
"four": {
"five": 5,
"seven": {
"nine": 9
}
}
}
$ echo '{"one": 1, "two": 2, "three": 3, "four": {"five": 5, "six": 6, "seven": {"eight": 8, "nine": 9}}}' | \
> niet .four -d six -d seven.eight
{
"five": 5,
"seven": {
"nine": 9
}
Another things that need to be explicit in the documentation of this function is that we can only remove entire keys from a given structure.
I mean we couldn't remove an element from a list where the list is the value of a given key.
Example:
$ echo '{"one": 1, "two": 2, "three": 3, "four": {"five": 5, "six": [1, 2, 3], "seven": {"eight": 8, "nine": 9}}}' | \
> niet .four -d "four.six[0]"
{
"five": 5,
"six": [
1,
2,
3
],
"seven": {
"eight": 8,
"nine": 9
}
}
In the previous example users can expect to can remove the index 0 from the node four.six
where six
is a list.
It can become possible by adapting the search algorithm and by introducing a similar syntax than jmespath
.
Do you still want to work on that? Else I think we can abandon this pull request.
Abandoning this PR as it didn't showed us recent activity
Some feedback:
You've some issues in your code:
I receive
cur_search=[".six", "seven.eight"]
andinput_dict=2
, after 1 iteration of your recursive calls I gotcur_search="six"
andinput_dict=2
.The issue here is that you consider always your
input
as a python dict, but with this use case we work on the subsettwo
only and so we only got the value of this key (2
), so I think you need to skip deletion wheninput_dict
is not a dict.