Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
jsonpath support mysql syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Nov 5, 2020
1 parent 1ccd0f1 commit 13f3f2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/alibaba/fastjson/JSONPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public Object extract(DefaultJSONParser parser) {
}

Segment lastSegment = segments[segments.length - 1];
if (lastSegment instanceof TypeSegment || lastSegment instanceof FloorSegment) {
if (lastSegment instanceof TypeSegment
|| lastSegment instanceof FloorSegment
|| lastSegment instanceof MultiIndexSegment) {
return eval(
parser.parse());
}
Expand Down Expand Up @@ -1021,6 +1023,12 @@ Object parseArrayAccessFilter(boolean acceptBracket) {
}

if (acceptBracket && ch == ']') {
if (isEOF()) {
if (propertyName.equals("last")) {
return new MultiIndexSegment(new int[]{-1});
}
}

next();
Filter filter = new NotNullSegement(propertyName, false);
while (ch == ' ') {
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/alibaba/json/bvt/path/JSONPath_17.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public void test_for_jsonpath() throws Exception {
String oupput = JSON.parse(input).toString();
assertEquals(obj, JSON.parse(oupput));
}

public void test_for_jsonpath_1() throws Exception {
assertEquals("[5]", JSONPath.extract("[1, 2, 3, 4, 5]", "$[last]").toString());
}
}

0 comments on commit 13f3f2b

Please sign in to comment.