As a small note, according to http://clojure.org/reader, Clojure keywords and symbols are allowed to contain only alphanumeric characters, *, +, !, -, _, and ?. Spaces aren’t allowed, but the keyword function allows them anyway because it doesn’t do any checking for validity for performance. I’m told that it’s up to the programmer to make sure that only valid keywords are created.
I agree that clojure.contrib.json should default to string keys, because keywords are so limited. The thing is, when clojure.contrib.json *does* convert JSON keys into Clojure keywords, should it check for validity and fail when it cannot create a valid keyword? On Feb 27, 3:24 pm, MarkSwanson <mark.swanson...@gmail.com> wrote: > Actually, I shouldn't have worded this as a json issue. It's really a > core problem that keywords with spaces can't be serialized/ > deserialized. > A keyword is basically a String, and the language definition does not > preclude keywords from having spaces. > (keyword "a b c") works, and so does (get m (keyword "a b c")) - on an > appropriately created map > > Cheers. > > On Feb 27, 3:55 pm, MarkSwanson <mark.swanson...@gmail.com> wrote: > > > > > Hello, > > > Consider the following valid JSON: > > > Clojure=> (def mq "{\"Question one\":\"test\"}") > > #'user/mq > > Clojure=> (read-json mq) > > {:Question one "test"} > > > So the default behaviour fails to work correctly for a common case. > > > The Clojure failure is not exactly obvious either: > > > (read-string (str mq)) > > > request failed java.lang.RuntimeException: > > java.lang.ArrayIndexOutOfBoundsException: 19 > > at clojure.lang.RT.readString(RT.java:1220) > > at clojure.core$read_string__4163.invoke(core.clj:2517) > > > I also tried with print-dup and it fails the same way: > > =>(def ms (new StringWriter)) > > =>(print-dup mq ms) > > =>(. ms toString) > > "#=(clojure.lang.PersistentArrayMap/create {:Question one \"test\"})" > > =>(read-string (. ms toString)) > > #<CompilerException java.lang.RuntimeException: > > java.lang.ArrayIndexOutOfBoundsException: 3 (REPL:65)> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en