stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
457 stars 97 forks source link

TypeError: string indices must be integers #131

Closed JulienPalard closed 3 years ago

JulienPalard commented 3 years ago

When provided with an invalid patch, like by forgetting to embed the operation in a list:

>>> import jsonpatch
>>> jsonpatch.JsonPatch({'op': 'add', 'path': '/foo', 'value': 'bar'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mdk/clones/meltygroup/kisee/.venv/lib/python3.8/site-packages/jsonpatch.py", line 561, in __init__
    self._get_operation(op)
  File "/home/mdk/clones/meltygroup/kisee/.venv/lib/python3.8/site-packages/jsonpatch.py", line 677, in _get_operation
    op = operation['op']
TypeError: string indices must be integers

I'd prefer something like an InvalidJsonPatch here.