As illustrated in this question (cljs.reader/read-string
) and this (clj->js
) the following should do the trick:
cljs.user=> (def data-as-str
"[{:dt [2017 6 30], :cashflow 431782}
{:dt [2018 6 30], :cashflow 452271}
{:dt [2019 6 30], :cashflow 473785}
{:dt [2020 6 30], :cashflow 496374}]")
#'cljs.user/data-as-str
cljs.user=> (cljs.reader/read-string data-as-str)
[{:dt [2017 6 30], :cashflow 431782}
{:dt [2018 6 30], :cashflow 452271}
{:dt [2019 6 30], :cashflow 473785}
{:dt [2020 6 30], :cashflow 496374}]
; i have little experience in cljs but this should deliver
; a plain old js object
cljs.user=> (clj->js (cljs.reader/read-string data-as-str))
#js [#js {:dt #js [2017 6 30], :cashflow 431782}
#js {:dt #js [2018 6 30], :cashflow 452271}
#js {:dt #js [2019 6 30], :cashflow 473785}
#js {:dt #js [2020 6 30], :cashflow 496374}]
from here on you could do whatever JSON.___ or other js-json lib provides
for example:
cljs.user=> (.stringify js/JSON
(clj->js (cljs.reader/read-string data-as-str)))
"[{\"dt\":[2017,6,30],\"cashflow\":431782},{\"dt\":[2018,6,30],\"cashflow\":452271},{\"dt\":[2019,6,30],\"cashflow\":473785},{\"dt\":[2020,6,30],\"cashflow\":496374}]"