This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-03
Channels
- # announcements (3)
- # babashka (29)
- # beginners (95)
- # calva (109)
- # cider (16)
- # clj-kondo (6)
- # clj-together (1)
- # cljdoc (2)
- # cljsrn (2)
- # clojure (85)
- # clojure-europe (26)
- # clojure-india (1)
- # clojure-seattle (1)
- # clojure-uk (6)
- # clojurescript (14)
- # conjure (4)
- # cursive (8)
- # datomic (6)
- # emacs (21)
- # events (1)
- # figwheel-main (5)
- # fulcro (11)
- # graalvm (32)
- # graphql (1)
- # holy-lambda (7)
- # humbleui (7)
- # jobs (3)
- # membrane (8)
- # nextjournal (31)
- # off-topic (29)
- # pathom (14)
- # polylith (9)
- # portal (16)
- # practicalli (4)
- # reitit (17)
- # releases (1)
- # remote-jobs (2)
- # ring (4)
- # sci (20)
- # shadow-cljs (24)
- # sql (1)
- # vim (12)
- # xtdb (3)
I'm attempting to use the camel-snake-kebab library in a clojurescript project. According to the docs, this code should work with both clojure and clojurescript. I added the appropriate :require to my namespace:
(ns atlas.rendering
(:require
[camel-snake-kebab.core :as csk]))
and added the proper dependency to my shadow-cljs.edn file:
:dependencies
[[camel-snake-kebab "0.4.2"]]
This should work, but I get an error:
The required namespace "camel-snake-kebab.core" is not available, it was required by "atlas/rendering.cljs".
Obviously, there's some reason why cljs isn't finding the library, but I have no idea why. Does anyone have any suggestions?In clojurescript is there any way to convert from json -> edn passing keys to a keyword conversion function? The keys in my json are camel-cased and I'd like to convert them to kebab case, rather than just converting the camel-cased keys to keywords. I've looked at js->clj, but it seems to only take a boolean parameter :keywordize-keys and not a function to convert keys. Is there another library I could use that would allow me to do this? Alternatively, is there an easy way to recursively walk the converted edn converting the map keys after the fact?
The implementation of js->clj
is rather trivial and given that you deal with JSON and not arbitrary JS objects, you can simplify it even further - it just recursively walks the data structure and replaces what it can.
Alternatively, you can use clojure.walk
. Doesn't matter that much.
Just in case - note that you needs depth-first traversal, so it would be clojure.walk/postwalk
.
Yes. I used that. It was a bit trickier reading in the JSON and getting it translated into JSON objects before converting it to EDN, but once that was done, getting the keywords correct was relatively simple. Thanks again for your help.
> It was a bit trickier reading in the JSON and getting it translated into JSON
What do you mean? It should be as simple as calling js/JSON.parse
on a string.
I had the json code in a resource file and had to get that into the code. Which sent me onto a macro adventure so I could slurp it into the cljs. The good news is that I now know how to use macros in cljs.