diff --git a/project.clj b/project.clj index ba88995..6f3c1e8 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject json-path "0.3.0" +(defproject json-path "0.3.0-local" :description "JSON Path for Clojure data structures" :url "http://github.com/gga/json-path" :dependencies [[org.clojure/clojure "1.5.0"]] diff --git a/src/json_path/walker.clj b/src/json_path/walker.clj index 3dc5b75..3ca3d29 100644 --- a/src/json_path/walker.clj +++ b/src/json_path/walker.clj @@ -42,8 +42,7 @@ (let [sel (nth sel-expr 1)] (if (= "*" sel) (:current context) - (nth (:current context) (Integer/parseInt sel)))) - (throw (Exception. "object must be an array."))) + (nth (:current context) (Integer/parseInt sel) nil)))) (= :filter (first sel-expr)) (filter #(eval-expr (nth sel-expr 1) (assoc context :current %)) (:current context)))) (defn walk [[opcode operand continuation] context] diff --git a/test/json_path/test/walker_test.clj b/test/json_path/test/walker_test.clj index 4681743..63a123d 100644 --- a/test/json_path/test/walker_test.clj +++ b/test/json_path/test/walker_test.clj @@ -36,8 +36,8 @@ {:current [{:bar "wrong"} {:bar "baz"}]}) => [{:bar "baz"}]) (fact "selecting places constraints on the shape of the object being selected from" - (walk-selector [:index "1"] {:current {:foo "bar"}}) => (throws Exception) - (walk-selector [:index "*"] {:current {:foo "bar"}}) => (throws Exception)) + (walk-selector [:index "1"] {:current {:foo "bar"}}) => nil + (walk-selector [:index "*"] {:current {:foo "bar"}}) => nil) (facts (walk [:path [[:root]]] {:root ...json...}) => ...json...