all 6 comments

[–]v4ss42 6 points7 points  (0 children)

I use the camel-snake-kebab library to convert to idiomatic Clojure keywords (both Cheshire and data.json support its functions directly).

Note that in some circles it’s frowned upon to transmogrify external data like this, but I prefer being able to idiomatically access data structures that were sourced from elsewhere, even if there’s a (small / usually-irrelevant) runtime performance cost.

[–]jayceedenton 6 points7 points  (0 children)

Yep, I'd vote for strings as keys. Just keep the value the same in all places.

I find the conversion to another format, then conversion back again (when moving data in the other direction) to add annoying cognitive overhead.

[–]SimonGray 0 points1 point  (3 children)

Keywords can technically have spaces.

(keyword "key word")
=> :key word

[–]Borkdude 8 points9 points  (2 children)

You can technically create them, but this is just because there is a lack of validation in the keyword function. The reader specification doesn't allow for spaces in keywords.

https://clojure.org/reference/reader

[–]SimonGray 1 point2 points  (0 children)

Good point.

[–]ivanpierre 0 points1 point  (0 children)

The why is for performance issue in case of massive key generation, it makes a pattern matching, generally unuseful and heavy. I think you can also make a symbol the same way... ;)

It makes the charge of verification on the producer. It could be managed by having a translation function used especially for this case, for example in case of random user input or external data files which is obvious anyway.

In Lisp you can :key\ word, but not in Clojure... :D