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

Creates function to know if a jsonPath is a function or not #867

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ public <T> T read(InputStream jsonInputStream, String charset, Configuration con
}
}

/**
* As JsonPath accepts a vary number of functions like min(), max(),
* avg(), stddev(), length(), sum(), keys(), concat(X), append(X),
* this function will return true if the path is a function
*
* @return true if the path is a function
*/
public Boolean isFunctionPath() {
return path.isFunctionPath();
}

// --------------------------------------------------------
//
// Static factory methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ public void a_function_can_be_compiled() {
assertThat(compile("$.aaa.foo(5,10,15)").toString()).isEqualTo("$['aaa'].foo(...)");
}

@Test
public void path_is_a_function() {
assertThat(compile("concat($.aaa, $.bbb)").isFunctionPath()).isTrue();
assertThat(compile("$.aaa").isFunctionPath()).isFalse();
}

@Test(expected = InvalidPathException.class)
public void array_indexes_must_be_separated_by_commas() {
compile("$[0, 1, 2 4]");
Expand Down