cheshire icon indicating copy to clipboard operation
cheshire copied to clipboard

Date's don't default to ISO formatting when in the key position

Open fivetran opened this issue 10 years ago • 3 comments

generate-string formats dates as strings. But it does that differently when the same date is in the key versus value position:

(require 'cheshire.core)
(import 'java.util.Date)
(def now (Date.))
(cheshire.core/generate-string {now now})

=> "{\"Thu Apr 17 15:39:35 PDT 2014\":\"2014-04-17T22:39:35Z\"}"

This is surprising.

fivetran avatar Apr 17 '14 22:04 fivetran

My guess is that keys are simply coerced to strings.

michaelklishin avatar Apr 17 '14 22:04 michaelklishin

This is because keys are assumed to be either "stringy", or as keywords. So the key Date is just having .toString called on it.

dakrone avatar Apr 17 '14 22:04 dakrone

See: https://github.com/dakrone/cheshire/blob/master/src/cheshire/generate.clj#L67-L69

dakrone avatar Apr 17 '14 22:04 dakrone