Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get error that is Function with name: first does not exist. #876

Open
lush-99 opened this issue Dec 1, 2022 · 3 comments
Open

I get error that is Function with name: first does not exist. #876

lush-99 opened this issue Dec 1, 2022 · 3 comments

Comments

@lush-99
Copy link

lush-99 commented Dec 1, 2022

my code

        ReadContext rct = JsonPath.parse(JsonUtil.getJsonByFileUtils(rateJsonFilePath));
        Object data = rct.read("$.data.items");
        log.info("data:{}", data);
        Object first = rct.read("$.data.items.first()");
        log.info("first:{}", first);

print

02:08:58.437 [main] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $['data']['items']
02:08:58.437 [main] INFO com.example.demo.jsontest.JsonTest - data:[{"id":1,"app_local":"ff","tax_rate":10,"basic_rate":15.5,"expected_profit_rate":10,"update_user":"yyyyyy","update_time":1669819482},{"id":1,"app_local":"rr","tax_rate":10,"basic_rate":15.5,"expected_profit_rate":10,"update_user":"wxxxxxx","update_time":1669819482}]
02:08:58.437 [main] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $['data']['items'].first()
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64)
Caused by: com.jayway.jsonpath.InvalidPathException: Function with name: first does not exist.
	at com.jayway.jsonpath.internal.function.PathFunctionFactory.newFunction(PathFunctionFactory.java:71)
	at com.jayway.jsonpath.internal.path.FunctionPathToken.evaluate(FunctionPathToken.java:38)
	at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:90)
	at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:80)
	at com.jayway.jsonpath.internal.path.PathToken.handleObjectProperty(PathToken.java:90)
	at com.jayway.jsonpath.internal.path.PropertyPathToken.evaluate(PropertyPathToken.java:80)
	at com.jayway.jsonpath.internal.path.RootPathToken.evaluate(RootPathToken.java:66)
	at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:99)
	at com.jayway.jsonpath.internal.path.CompiledPath.evaluate(CompiledPath.java:107)
	at com.jayway.jsonpath.JsonPath.read(JsonPath.java:179)
	at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:88)
	at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:77)
	at com.example.demo.jsontest.JsonTest.main(JsonTest.java:58)
	... 5 more

the data is:

[
      {
        "id": 1,
        "app_local": "ff",
        "tax_rate": 10,
        "basic_rate": 15.5,
        "expected_profit_rate": 10,
        "update_user": "yyyyyy",
        "update_time": 1669819482
      },
      {
        "id": 1,
        "app_local": "rr",
        "tax_rate": 10,
        "basic_rate": 15.5,
        "expected_profit_rate": 10,
        "update_user": "wxxxxxx",
        "update_time": 1669819482
      }
    ]
@iblislin
Copy link

I think the first() function is still not available in v2.7.0

@harry77914
Copy link

Should we remove it from documenation, Its misleading

@lush-99
Copy link
Author

lush-99 commented Jun 13, 2023

yes, i think so

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

No branches or pull requests

3 participants