Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -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"]]
Expand Down
3 changes: 1 addition & 2 deletions src/json_path/walker.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions test/json_path/test/walker_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down