aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/format/json.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/format/json.lux22
1 files changed, 14 insertions, 8 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index 60d57abab..c42093710 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -51,6 +51,10 @@
[Object (Dictionary String JSON)]
)
+(def: #export object
+ (-> (List [String JSON]) JSON)
+ (|>> (dictionary.from-list text.hash) #..Object))
+
(syntax: #export (json token)
{#.doc (doc "A simple way to produce JSON literals."
(json #1)
@@ -66,15 +70,15 @@
(^template [<ast-tag> <ctor> <json-tag>]
[_ (<ast-tag> value)]
(wrap (list (` (: JSON (<json-tag> (~ (<ctor> value))))))))
- ([#.Bit code.bit #Boolean]
- [#.Frac code.frac #Number]
- [#.Text code.text #String])
+ ([#.Bit code.bit #..Boolean]
+ [#.Frac code.frac #..Number]
+ [#.Text code.text #..String])
[_ (#.Tag ["" "null"])]
- (wrap (list (` (: JSON #Null))))
+ (wrap (list (` (: JSON #..Null))))
[_ (#.Tuple members)]
- (wrap (list (` (: JSON (#Array ((~! row) (~+ (list@map wrapper members))))))))
+ (wrap (list (` (: JSON (#..Array ((~! row) (~+ (list@map wrapper members))))))))
[_ (#.Record pairs)]
(do ..monad
@@ -87,7 +91,9 @@
_
(macro.fail "Wrong syntax for JSON object.")))
pairs)]
- (wrap (list (` (: JSON (#Object ((~! dictionary.from-list) (~! text.hash) (list (~+ pairs')))))))))
+ (wrap (list (` (: JSON (#..Object ((~! dictionary.from-list)
+ (~! text.hash)
+ (list (~+ pairs')))))))))
_
(wrap (list token)))))
@@ -115,7 +121,7 @@
(#try.Failure ($_ text@compose "Missing field '" key "' on object.")))
_
- (#try.Failure ($_ text@compose "Cannot get field '" key "' of a non-object."))))
+ (#try.Failure ($_ text@compose "Cannot get field '" key "' on a non-object."))))
(def: #export (set key value json)
{#.doc "A JSON object field setter."}
@@ -125,7 +131,7 @@
(#try.Success (#Object (dictionary.put key value obj)))
_
- (#try.Failure ($_ text@compose "Cannot set field '" key "' of a non-object."))))
+ (#try.Failure ($_ text@compose "Cannot set field '" key "' on a non-object."))))
(template [<name> <tag> <type> <desc>]
[(def: #export (<name> key json)