Browse Source

Merge branch 'json-path:master' into patch-1

pull/909/head
Dat Vu 2 years ago committed by GitHub
parent
commit
9e156c5ec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      README.md
  2. 11
      build.gradle
  3. 10
      json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

42
README.md

@ -11,6 +11,8 @@ Jayway JsonPath is a Java port of [Stefan Goessner JsonPath implementation](http
News News
---- ----
26 Mar 2023 - Released JsonPath 2.8.0
30 Jan 2022 - Released JsonPath 2.7.0 30 Jan 2022 - Released JsonPath 2.7.0
02 Jun 2021 - Released JsonPath 2.6.0 02 Jun 2021 - Released JsonPath 2.6.0
@ -43,7 +45,7 @@ JsonPath is available at the Central Maven Repository. Maven users add this to y
<dependency> <dependency>
<groupId>com.jayway.jsonpath</groupId> <groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId> <artifactId>json-path</artifactId>
<version>2.7.0</version> <version>2.8.0</version>
</dependency> </dependency>
``` ```
@ -165,25 +167,25 @@ Given the json
} }
``` ```
| JsonPath (click link to try)| Result | | JsonPath | Result |
| :------- | :----- | |:-------------------------------------------------------------------| :----- |
| <a href="http://jsonpath.herokuapp.com/?path=$.store.book[*].author" target="_blank">$.store.book[*].author</a>| The authors of all books | | $.store.book[*].author | The authors of all books |
| <a href="http://jsonpath.herokuapp.com/?path=$..author" target="_blank">$..author</a> | All authors | | $..author | All authors |
| <a href="http://jsonpath.herokuapp.com/?path=$.store.*" target="_blank">$.store.*</a> | All things, both books and bicycles | | $.store.* | All things, both books and bicycles |
| <a href="http://jsonpath.herokuapp.com/?path=$.store..price" target="_blank">$.store..price</a> | The price of everything | | $.store..price | The price of everything |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[2]" target="_blank">$..book[2]</a> | The third book | | $..book[2] | The third book |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[-2]" target="_blank">$..book[-2]</a> | The second to last book | | $..book[-2] | The second to last book |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[0,1]" target="_blank">$..book[0,1]</a> | The first two books | | $..book[0,1] | The first two books |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[:2]" target="_blank">$..book[:2]</a> | All books from index 0 (inclusive) until index 2 (exclusive) | | $..book[:2] | All books from index 0 (inclusive) until index 2 (exclusive) |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[1:2]" target="_blank">$..book[1:2]</a> | All books from index 1 (inclusive) until index 2 (exclusive) | | $..book[1:2] | All books from index 1 (inclusive) until index 2 (exclusive) |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[-2:]" target="_blank">$..book[-2:]</a> | Last two books | | $..book[-2:] | Last two books |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[2:]" target="_blank">$..book[2:]</a> | All books from index 2 (inclusive) to last | | $..book[2:] | All books from index 2 (inclusive) to last |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[?(@.isbn)]" target="_blank">$..book[?(@.isbn)]</a> | All books with an ISBN number | | $..book[?(@.isbn)] | All books with an ISBN number |
| <a href="http://jsonpath.herokuapp.com/?path=$.store.book[?(@.price < 10)]" target="_blank">$.store.book[?(@.price < 10)]</a> | All books in store cheaper than 10 | | $.store.book[?(@.price < 10)] | All books in store cheaper than 10 |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[?(@.price <= $['expensive'])]" target="_blank">$..book[?(@.price <= $['expensive'])]</a> | All books in store that are not "expensive" | | $..book[?(@.price <= $['expensive'])] | All books in store that are not "expensive" |
| <a href="http://jsonpath.herokuapp.com/?path=$..book[?(@.author =~ /.*REES/i)]" target="_blank">$..book[?(@.author =~ /.*REES/i)]</a> | All books matching regex (ignore case) | | $..book[?(@.author =~ /.*REES/i)] | All books matching regex (ignore case) |
| <a href="http://jsonpath.herokuapp.com/?path=$..*" target="_blank">$..*</a> | Give me every thing | $..* | Give me every thing
| <a href="http://jsonpath.herokuapp.com/?path=$..book.length()" target="_blank">$..book.length()</a> | The number of books | | $..book.length() | The number of books |
Reading a Document Reading a Document
------------------ ------------------

11
build.gradle

@ -19,7 +19,7 @@ ext {
hamcrest: 'org.hamcrest:hamcrest:2.2', hamcrest: 'org.hamcrest:hamcrest:2.2',
jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.14.2', jacksonDatabind: 'com.fasterxml.jackson.core:jackson-databind:2.14.2',
jettison: 'org.codehaus.jettison:jettison:1.5.4', jettison: 'org.codehaus.jettison:jettison:1.5.4',
jsonOrg: 'org.json:json:20140107', jsonOrg: 'org.json:json:20230227',
tapestryJson: 'org.apache.tapestry:tapestry-json:5.8.1', tapestryJson: 'org.apache.tapestry:tapestry-json:5.8.1',
jakartaJsonP: 'jakarta.json:jakarta.json-api:2.0.1', jakartaJsonP: 'jakarta.json:jakarta.json-api:2.0.1',
jakartaJsonB: 'jakarta.json.bind:jakarta.json.bind-api:2.0.0', jakartaJsonB: 'jakarta.json.bind:jakarta.json.bind-api:2.0.0',
@ -53,7 +53,7 @@ allprojects {
ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss') ext.buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss')
group = 'com.jayway.jsonpath' group = 'com.jayway.jsonpath'
version = '2.8.0' + (snapshotVersion ? "-SNAPSHOT" : "") version = '2.9.0' + (snapshotVersion ? "-SNAPSHOT" : "")
} }
@ -87,9 +87,8 @@ subprojects {
} }
signing { signing {
sign configurations.archives sign publishing.publications
//sign publishing.publications.mavenJava required { !snapshotVersion && gradle.taskGraph.hasTask("publish") }
required { !snapshotVersion && gradle.taskGraph.hasTask("publish") } // uploadArchives is replaced by publish
} }
javadoc { javadoc {
@ -122,7 +121,7 @@ subprojects {
pom { pom {
name = jar.baseName name = jar.baseName
description = project.description description = 'A library to query and verify JSON'
url = 'https://github.com/jayway/JsonPath' url = 'https://github.com/jayway/JsonPath'
licenses { licenses {

10
json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

@ -4,6 +4,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -73,9 +74,14 @@ public class InlineFilterTest extends BaseTest {
@Test @Test
public void root_context_can_be_referred_in_predicate() { public void root_context_can_be_referred_in_predicate() {
List<Double> prices = using(conf).parse(JSON_DOCUMENT).read("store.book[?(@.display-price <= $.max-price)].display-price", List.class); List<?> prices = using(conf).parse(JSON_DOCUMENT).read("store.book[?(@.display-price <= $.max-price)].display-price", List.class);
assertThat(prices).containsAll(asList(8.95D, 8.99D)); assertThat(prices.stream().map(this::asDouble)).containsAll(asList(8.95D, 8.99D));
}
private Double asDouble(Object object) {
// For json-org implementation returns a list of big decimals
return object instanceof BigDecimal ? ((BigDecimal) object).doubleValue() : (Double) object;
} }
@Test @Test

Loading…
Cancel
Save