h2non / jsonpath-ng

Finally, a JSONPath implementation for Python that aims to be standard compliant. That's all. Enjoy!
Apache License 2.0
582 stars 85 forks source link

Updating a json object fails if the value of a key is boolean #73

Open Andrewnopoulos opened 3 years ago

Andrewnopoulos commented 3 years ago

Related to https://github.com/h2non/jsonpath-ng/issues/47

Steps to reproduce:

from jsonpath_ng import parse
selector = '$.*.number'
data = {
    'foo': ['abc', 'def'],
    'bar': {'number': 123456},
    'boolean': True
}
val = '98765'
expr = parse(selector)
expr.update(data, val)

Expected

'number' field to be updated to '98765'.

Observed

  File "/home/andrew/test.py", line 12, in <module>
    expr.update(data, val)
  File "/home/andrew/jsonpath_ng/jsonpath.py", line 261, in update
    self.right.update(datum.value, val)
  File "/home/andrew/jsonpath_ng/jsonpath.py", line 526, in update
    if field in data:
TypeError: argument of type 'bool' is not iterable