h2non / jsonpath-ng

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

Don't clobber existing IDs with 'auto_id' #98

Closed Andrew-Sheridan closed 11 months ago

Andrew-Sheridan commented 2 years ago

In https://github.com/kennknowles/python-jsonpath-rw/pull/96 @snopoke says:

The docs for 'auto_id_field' says:

If you set jsonpath_rw.auto_id_field to a value other than None, then for any piece of data missing that field, it will be replaced by the JSONPath to it, giving automatic unique ids to any piece of data. These ids will take into account any ids already present as well.

This is not really true since even if the node has an 'id' field it will get replaced with an 'auto_id' field. This gives unexpected results:

jsonpath_rw.auto_id_field = "id"
parse(''foo.baz.id'').find({'foo': {'baz': {'id': 'hi'}}})
> 'foo.hi'  # which should really just be 'hi'

The code change @snopoke looks pretty straightforward: https://github.com/kennknowles/python-jsonpath-rw/pull/96/files

michaelmior commented 11 months ago

This should be resolved now.