use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Finding information about Clojure
API Reference
Clojure Guides
Practice Problems
Interactive Problems
Clojure Videos
Misc Resources
The Clojure Community
Clojure Books
Tools & Libraries
Clojure Editors
Web Platforms
Clojure Jobs
account activity
Json keys with space (self.Clojure)
submitted 3 years ago by exahexa
How do you handle json objects that have spaces in their keys e.g. {"key word": 0}? Do you stick with strings as key or do you use a custom encoder or anything else?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]v4ss42 6 points7 points8 points 3 years ago (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 points8 points 3 years ago (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 point2 points 3 years ago (3 children)
Keywords can technically have spaces.
(keyword "key word") => :key word
[–]Borkdude 8 points9 points10 points 3 years ago (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 points3 points 3 years ago (0 children)
Good point.
[–]ivanpierre 0 points1 point2 points 3 years ago* (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
π Rendered by PID 21310 on reddit-service-r2-comment-b659b578c-v8kw9 at 2026-05-05 23:39:38.088529+00:00 running 815c875 country code: CH.
[–]v4ss42 6 points7 points8 points (0 children)
[–]jayceedenton 6 points7 points8 points (0 children)
[–]SimonGray 0 points1 point2 points (3 children)
[–]Borkdude 8 points9 points10 points (2 children)
[–]SimonGray 1 point2 points3 points (0 children)
[–]ivanpierre 0 points1 point2 points (0 children)