-
Notifications
You must be signed in to change notification settings - Fork 6
/
json.cljc
42 lines (34 loc) · 904 Bytes
/
json.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(ns axel-f.functions.json
(:require [axel-f.functions.core :refer [def-excel-fn]]
#?(:clj [cheshire.core :as json])))
(defn json-encode
[to-encode]
#?(:clj
(json/generate-string to-encode)
:cljs
(js/JSON.stringify (clj->js to-encode))))
(def json-encode-meta
{:args [{:desc "Object to be encoded"}]
:desc "Returns a JSON-encoding String for the given object."})
(defn json-decode
[to-decode]
#?(:clj
(json/parse-string to-decode)
:cljs
(js->clj (js/JSON.parse to-decode))))
(def json-decode-meta
{:args [{:desc "JSON-encoded string to be decoded"}]
:desc "Returns an object corresponding to the given JSON-encoded string."})
(def-excel-fn
"JSONENCODE"
json-encode
json-encode-meta
"JSON.ENCODE"
json-encode
json-encode-meta
"JSONDECODE"
json-decode
json-decode-meta
"JSON.DECODE"
json-decode
json-decode-meta)