kennknowles / python-jsonpath-rw

A robust and significantly extended implementation of JSONPath for Python, with a clear AST for metaprogramming.
Apache License 2.0
603 stars 194 forks source link

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

Closed snopoke closed 3 years ago

snopoke commented 3 years ago

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'