malli

Chiffa 2025-08-03T21:13:50.426339Z

Hello, I'm fairly new to Clojure, so sorry in advance I've been trying to migrate an autogenerated spec+spec-tools API endpoint spec to Malli, and it returns a stringified Instant as one of the fields. I've been trying to convert it to an actual java.time.Instant type, but I'm not sure how to parse it before validating. Using :time/instant from experimental time fails, so does the approach below, so I'm not sure how to do this sanely

(defn parse-iso8601-string-native [s]
  (tick/instant s))

(def new-status-response-schema
  (l/schema
    {:data
     {
      :version           :string
      :server_time       [:fn parse-iso8601-string-native] ;field in question
      }}))
json
{
  "data": {
    "version": "string",
    "server_time": "2019-08-24T14:15:22Z"
  }
}

Chiffa 2025-08-07T12:50:37.020479Z

Sorry for the delayed response, didn't see the message Using :time/instant directly fails validation on my example json. I assume that's because I need to transform the data and not just provide the schema

(def test-schema
  (l/schema
    {:data
     {
      :version     :string
      :server_time :time/instant
      }
     }
    ))

(def test-data
  (json/parse-string
    "{\n  \"data\": {\n    \"version\": \"string\",\n    \"server_time\": \"2019-08-24T14:15:22Z\" }}}" true))

 (m/validate test-schema test-data)
=> false

(m/explain test-schema test-data)
=>
{:schema [:map [:data [:map [:version :string] [:server_time :time/instant]]]],
 :value {:data {:version "string", :server_time "2019-08-24T14:15:22Z"}},
 :errors ({:path [:data :server_time 0], :in [:data :server_time], :schema :time/instant, :value "2019-08-24T14:15:22Z"})}
Doing it the [:fn parse] validates the type correctly but doesn't transform it, while I want both to happen

Matti Uusitalo 2025-08-04T07:18:58.054779Z

Hello! I'm interested to hear how using :time/instant was failing for you?