diff --git a/README b/README
index 6d13e082..7870c033 100644
--- a/README
+++ b/README
@@ -1 +1 @@
-Java DSL for testing and reading JSON documents
\ No newline at end of file
+Java DSL for reading and testing JSON documents.
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
deleted file mode 100644
index a7dfc861..00000000
--- a/examples/pom.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
- 4.0.0
-
- json-path-parent
- com.jayway.jsonpath
- 1.0-SNAPSHOT
-
- com.jayway.jsonassert
- examples
- 1.0-SNAPSHOT
- examples
- http://maven.apache.org
-
-
-
diff --git a/json-path-assert/pom.xml b/json-path-assert/pom.xml
index bae633d3..b4acf59d 100644
--- a/json-path-assert/pom.xml
+++ b/json-path-assert/pom.xml
@@ -1,4 +1,19 @@
+
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/CollectionMatcher.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/CollectionMatcher.java
index cfb30549..364aa885 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/CollectionMatcher.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/CollectionMatcher.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import org.hamcrest.BaseMatcher;
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java
index 23c10cd5..cef7e0b0 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsCollectionWithSize.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import static org.hamcrest.core.IsEqual.equalTo;
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsEmptyCollection.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsEmptyCollection.java
index 0ee7edc6..23b12d07 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsEmptyCollection.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsEmptyCollection.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import org.hamcrest.Description;
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingKey.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingKey.java
index abe3bd25..58bfc239 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingKey.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingKey.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import java.util.Map;
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingValue.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingValue.java
index 4fd99495..9a4b08a4 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingValue.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/IsMapContainingValue.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import org.hamcrest.Description;
diff --git a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/MapTypeSafeMatcher.java b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/MapTypeSafeMatcher.java
index 83a6652b..c52a20ef 100644
--- a/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/MapTypeSafeMatcher.java
+++ b/json-path-assert/src/main/java/com/jayway/jsonassert/impl/matcher/MapTypeSafeMatcher.java
@@ -1,3 +1,32 @@
+/*
+BSD License
+
+Copyright (c) 2000-2006, www.hamcrest.org
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions and the following disclaimer. Redistributions in binary form must reproduce
+the above copyright notice, this list of conditions and the following disclaimer in
+the documentation and/or other materials provided with the distribution.
+
+Neither the name of Hamcrest nor the names of its contributors may be used to endorse
+or promote products derived from this software without specific prior written
+permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+*/
package com.jayway.jsonassert.impl.matcher;
import org.hamcrest.BaseMatcher;
diff --git a/json-path/pom.xml b/json-path/pom.xml
index cff22f60..0cdf0300 100644
--- a/json-path/pom.xml
+++ b/json-path/pom.xml
@@ -1,3 +1,4 @@
+
-
4.0.0
@@ -29,19 +29,15 @@
json-pathhttp://maven.apache.org
-
com.googlecode.json-simplejson-simple
-
-
commons-langcommons-lang
-
-
+
diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
index c5b6e201..002dd787 100644
--- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
+++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java
@@ -12,10 +12,66 @@ import java.util.logging.Logger;
import static java.lang.String.format;
/**
- * Created by IntelliJ IDEA.
- * User: kallestenflo
+ * User: kalle stenflo
* Date: 2/2/11
* Time: 1:03 PM
+ *
+ * JsonPath is to JSON what XPATH is to XML, a simple way to extract parts of a given document. JsonPath is
+ * available in many programming languages such as Javascript, Python and PHP.
+ *
+ * JsonPath allows you to compile a json path string to use it many times or to compile and apply in one
+ * single on demand operation.
+ *
+ * Given the Json document:
+ *
+ *
+ * String json =
+ * "{
+ * "store":
+ * {
+ * "book":
+ * [
+ * {
+ * "category": "reference",
+ * "author": "Nigel Rees",
+ * "title": "Sayings of the Century",
+ * "price": 8.95
+ * },
+ * {
+ * "category": "fiction",
+ * "author": "Evelyn Waugh",
+ * "title": "Sword of Honour",
+ * "price": 12.99
+ * }
+ * ],
+ * "bicycle":
+ * {
+ * "color": "red",
+ * "price": 19.95
+ * }
+ * }
+ * }";
+ *
+ *
+ * A JsonPath can be compiled and used as shown:
+ *
+ *
+ * JsonPath path = JsonPath.compile("$.store.book[1]");
+ *
+ * List<Object> books = path.read(json);
+ *
+ *
+ * Or:
+ *
+ *
+ * List<Object> authors = JsonPath.read(json, "$.store.book[*].author")
+ *
+ *
+ * If the json path returns a single value (is definite):
+ *
+ *
+ * String author = JsonPath.read(json, "$.store.book[1].author")
+ *
*/
public class JsonPath {
@@ -25,47 +81,93 @@ public class JsonPath {
private JsonPathFilterChain filters;
- public static JsonPath compile(String jsonPath) {
- return new JsonPath(jsonPath);
- }
-
/**
* Creates a new JsonPath.
*
* @param jsonPath the path statement
*/
private JsonPath(String jsonPath) {
- if(jsonPath == null ||
- jsonPath.trim().isEmpty() ||
- jsonPath.matches("new ") ||
- jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\(")){
+ if (jsonPath == null ||
+ jsonPath.trim().isEmpty() ||
+ jsonPath.matches("new ") ||
+ jsonPath.matches("[^\\?\\+\\=\\-\\*\\/\\!]\\(")) {
- throw new InvalidPathException("Invalid path");
+ throw new InvalidPathException("Invalid path");
}
this.filters = new JsonPathFilterChain(PathUtil.splitPath(jsonPath));
}
+ /**
+ * Applies this json path to the provided object
+ *
+ * @param json a json Object
+ * @param
+ * @return list of objects matched by the given path
+ */
public List read(Object json) {
return (List) filters.filter(json);
}
+ /**
+ * Applies this json path to the provided object
+ *
+ * @param json a json string
+ * @param
+ * @return list of objects matched by the given path
+ */
public List read(String json) throws java.text.ParseException {
return read(parse(json));
}
+ /**
+ * Compiles a JsonPath from the given string
+ *
+ * @param jsonPath to compile
+ * @return compiled JsonPath
+ */
+ public static JsonPath compile(String jsonPath) {
+ return new JsonPath(jsonPath);
+ }
+
+ /**
+ * Creates a new JsonPath and applies it to the provided Json string
+ *
+ * @param json a json string
+ * @param jsonPath the json path
+ * @param
+ * @return list of objects matched by the given path
+ */
public static List read(String json, String jsonPath) throws java.text.ParseException {
return compile(jsonPath).read(json);
}
+ /**
+ * Creates a new JsonPath and applies it to the provided Json object
+ *
+ * @param json a json object
+ * @param jsonPath the json path
+ * @param
+ * @return list of objects matched by the given path
+ */
public static List read(Object json, String jsonPath) {
return compile(jsonPath).read(json);
}
+ /**
+ * Creates a new JsonPath and applies it to the provided Json object. Note this method
+ * will throw an exception if the provided path returns more than one object. This method
+ * can be used with paths that are not definite but a warning will be generated.
+ *
+ * @param json a json object
+ * @param jsonPath the json path
+ * @param
+ * @return the object matched by the given path
+ */
public static T readOne(Object json, String jsonPath) {
List