Skip to content

Conversation

jg-rp
Copy link
Owner

@jg-rp jg-rp commented Aug 25, 2025

Add the startswith function extension.

startswith returns True if both arguments are strings and the second argument is a prefix of the first argument. See the filter functions documentation.

Closes #49

@jg-rp jg-rp merged commit a03618b into main Aug 25, 2025
26 checks passed
@jg-rp jg-rp deleted the startswith-function branch August 25, 2025 08:17
@@ -13,6 +13,7 @@ These breaking changes apply to Python JSONPath in its default configuration. We

**JSONPath function extension changes**

- Added the `startswith(value, prefix)` function extension. `startswith` returns `True` if both arguments are strings and the second argument is a prefix of the first argument. See the [filter functions](https://jg-rp.github.io/python-jsonpath/functions/#startswith) documentation.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be implemented with regex, so this is for performance?

Copy link
Owner Author

@jg-rp jg-rp Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @He-Pin,

I have a use case where operators like and and or are preferable over && and ||, for example. Adding functions like startswith() where match() would do fits in well in that particular scenario.

Maybe non-standard function extension should be disabled in the new "strict" JSONPath environment 🤔

Copy link

@He-Pin He-Pin Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have something like this too, like isChiness to filter out Chinese text when we do TaoBao English.

Thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

startswith function extension
2 participants