diff options
Diffstat (limited to 'stdlib/source/lux/data/format/json.lux')
-rw-r--r-- | stdlib/source/lux/data/format/json.lux | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index b68101e3c..64064fb1f 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -2,6 +2,7 @@ "For more information, please see: http://www.json.org/")} [lux #* [control + pipe ["." monad (#+ Monad do)] [equivalence (#+ Equivalence)] codec @@ -192,19 +193,31 @@ ############################################################ ############################################################ -(def: (encode-boolean value) +(def: encode-boolean (-> Bit Text) - (case value - #0 "false" - #1 "true")) + (|>> (case> + #0 "false" + #1 "true"))) + +(def: encode-number + (-> Frac Text) + (|>> (case> + +0.0 "0.0" + -0.0 "0.0" + value (let [raw (:: frac.decimal encode value)] + (if (f/< +0.0 value) + raw + (|> raw (text.split 1) maybe.assume product.right)))))) (def: (show-null _) (-> Null Text) "null") + (do-template [<name> <type> <codec>] [(def: <name> (-> <type> Text) <codec>)] - [show-boolean Boolean encode-boolean] - [show-number Number (:: frac.decimal encode)] - [show-string String text.encode]) + [show-boolean Boolean ..encode-boolean] + [show-number Number ..encode-number] + [show-string String text.encode] + ) (def: (show-array show-json elems) (-> (-> JSON Text) (-> Array Text)) |