Skip to content

Conversation

@jg-rp
Copy link
Owner

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

This PR changes JSONPathEnvironment.setup_function_extensions() to skip registering non-standard functions when strict is True.

Standard functions are those defined by RFC 9535, count, length, match, search and value.

Non-standard, built-in function are:

  • isinstance (alias is)
  • typeof (alias type)
  • startswith
  • keys

@jg-rp jg-rp merged commit 35aea9e into main Aug 28, 2025
26 checks passed
@jg-rp jg-rp deleted the strict-function-extensions branch August 28, 2025 06:19
@He-Pin
Copy link

He-Pin commented Aug 28, 2025

Not sure if this is right, the rfc says we can register methods.

@jg-rp
Copy link
Owner Author

jg-rp commented Aug 28, 2025

Yeah, there's nothing stopping users registering non-standard functions with their own JSONPathEnvironment subclass. It's just that I'm offering two preconfigured environments. One with everything and one with things defined in RFC 9535 only.

Anything other than those two preconfigured environments, I expect users to do something like this.

from jsonpath import JSONPathEnvironment
from jsonpath.function_extensions import StartsWith


class MyJSONPathEnvironment(JSONPathEnvironment):
    def __init__(self) -> None:
        super().__init__(strict=True)

    def setup_function_extensions(self) -> None:
        super().setup_function_extensions()
        self.function_extensions["startswith"] = StartsWith()


jsonpath = MyJSONPathEnvironment()
query = jsonpath.compile("...")

Do you think this is a reasonable approach? I'll defiantly update the docs and to make this clearer.

@He-Pin
Copy link

He-Pin commented Aug 28, 2025

I think maybe just make sure the predefined one can not be overrided

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.

3 participants