You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Could set_pointer create structures if it can't find any? #41
>>> data = {}
>>> set_pointer(data, "/cat/name", "whiskers")
Traceback (most recent call last):
File "......./jsonpointer.py", line 276, in walk
return doc[part]
KeyError: 'cat'
During handling of the above exception, another exception occurred:
..........
raise JsonPointerException("member '%s' not found in %s" % (part, doc))
jsonpointer.JsonPointerException: member 'cat' not found in {}
Could there be an option (off by default) to create dicts/lists as it tries to set things? So instead you'd get:
NB: The spec would allow that, but it is not required
For example, some applications might stop pointer processing upon an error, while others may attempt to recover from missing values by inserting default ones.
>>> from jsonpointer import set_pointer
>>> obj = {'cities': {}}
>>> set_pointer(obj, '/cities/NewYork', '0')
>>> print(obj)
'cities': {'NewYork': '0'}}
>>> set_pointer(obj, '/cities/LosAngeles/population', '4mln')
>>> print(obj)
---------------------------------------------------------------------------
KeyError: 'LosAngeles'
...
JsonPointerException("member '%s' not found in %s" % (part, doc))
JsonPointerException: member 'LosAngeles' not found in {'NewYork': '0'}
@odscjames, currently it is possible to set a single missing level works, but it is not possible to go deeper. I think it might be useful to implement this feature recursively.
Activity
SquareByte commentedon Jan 18, 2022
NB: The spec would allow that, but it is not required
alb3rtom commentedon Nov 10, 2022
@odscjames, currently it is possible to set a single missing level works, but it is not possible to go deeper. I think it might be useful to implement this feature recursively.
stefankoegl commentedon Oct 7, 2026
There's a possible fix available in #84. What do you think?