Closed LQBing closed 1 year ago
I need make the json {'a': 'a', 'b': 'b'} remove a node 'b', the json need be {'a': 'a'}.
If use update() like blow code, the json will be {'a': 'a', 'b': None}. the node 'b' will still there.
json1 = {'a': 'a', 'b': 'b'} expr = parse('b') res = expr.update(json1, [])
I know the dict().pop(), but the jsonpath is not static. So dict().pop() is not working.
Hopefully the issue #44 which I have just raised will answer this. This will be a good test of the text I have proposed.
I was wondering this as well, until I saw filter() in another issue #44. However it turns out filter() is bugged: The filter() function does not work when there is a filter expression in the jsonpath, and it throws a NotImplementedError. Code to duplicate this error:
obj = {
"a": [
{"b": "X"},
{"b": "Y"}
]
}
jsonpath = parse("$.a[?(@.b==X)]")
matches = jsonpath.find(obj)
print(matches[0].value)
>>> {'b': 'X'} # find() returns correct value
result = jsonpath.filter(lambda x: True, obj)
>>> NotImplementedError # filter() throws error
Any news on this? Meanwhile I'm trying to get a temporary solution into this library.
L.E.: Made a PR for it: https://github.com/h2non/jsonpath-ng/pull/106
I need remove a node with a not special jsonpath, but I do not find any function looks like remove or delete. who can help me?