Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom conversion when parsing? #171

Open
ejstembler opened this issue Feb 21, 2021 · 0 comments
Open

Custom conversion when parsing? #171

ejstembler opened this issue Feb 21, 2021 · 0 comments

Comments

@ejstembler
Copy link

I have code which parses JSON; all keyword values are parsed as strings. Later, I map through the maps and overwrite one of the keywords with the date version of its string data. I have it broken out into two functions and it works. I'm wonding if there's a way to just have the parse function do this? In actuality I have two other elements which need to be converted to dates as well.

(ns clojure-json-test.core
  (:gen-class)
  (:require [clj-time.core :as t]
            [clj-time.format :as f]
            [clj-time.local :as l]
            [cheshire.core :refer :all]
            [org.httpkit.client :as client])
  (:import [java.net URI]
           [javax.net.ssl SNIHostName SSLEngine SSLParameters]))

;; other code snipped

(defn get-posts-body 
  []
  (:body @(client/get posts-url api-options)))

(defn get-posts
  []
  (parse-string (get-posts-body) true))

(defn get-posts-with-dates
  []
  (map #(merge % {:last_viewed_at (f/parse (f/formatters :date-time-no-ms) (:last_viewed_at %))}) (get-posts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant