I’m a beginner writing a weather app as my first little test program (the full code is below, minus the API key). When I do “lein run”, I get an error stating “no such namespace: json”. However, I explicitly required the json library, and I have it in my dependencies as folllows:
:dependencies [[org.clojure/clojure "1.11.1"] [clj-http "3.11.0"] [org.clojure/data.json "2.4.0"]]. What am I missing here? I have the dependency and I’ve imported the namespace. Thanks for the help!
:require [[clojure.data.json :as json]
[clj-http.client :as http]]))
(defn get-weather [lat lon api-key]
(let [url (str "http://api.openweathermap.org/data/3.0/onecall?lat="
lat "&lon=" lon "&appid=" api-key)]
(-> (http/get url)
"I don't do a whole lot ... yet."
(println (get-weather 32.832809 -117.271271 api-key)))
I think the problem is in your dependency, it should be:
Never mind, that’s what you have. I think we need to see your whole project definition. Can you share the entire project on Github? (Apart from your API key, of course, which ideally your code would obtain through an environment variable.)
Sure, here it is (minus the API key)! Let me know if there’s anything else I can help with
Awesome! I’ll take a look quickly. I was also about to post a link to where I use the exact same weather API in one of my own Clojure projects, although I use a different JSON parsing library: shade/weather.clj at main · brunchboy/shade · GitHub
Ah, yes, figured it out, it is a couple of structural problems in your namespace declaration. Try this version:
(:require [clojure.data.json :as json]
[clj-http.client :as http]))
That works, thank you! So then clojure’s keyword arguments require parentheses to be parsed correctly?
That’s not the issue (and is not true). The
ns macro is a complicated macro with its own structuring rules, you just need to invoke it correctly. You had passed your
:require declaration as arguments to your
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.