(.using
  [library
   [lux {"-" nat int rev list type or and}
    ["$" documentation {"+" documentation:}]
    [data
     [text {"+" \n}
      ["%" format {"+" format}]]]
    [macro
     ["[0]" template]]]]
  [\\library
   ["[0]" /]])

(documentation: /.json
  "A simple way to produce JSON literals."
  ["null"
   (json #null)]
  ["true"
   (json #1)]
  ["123.456"
   (json +123.456)]
  ["'this is a string'"
   (json "this is a string")]
  ["['this' 'is' 'an' 'array']"
   (json ["this" "is" "an" "array"])]
  ["{'this' 'is', 'an' 'object'}"
   (json {"this" "is" "an" "object"})])

(documentation: /.fields
  "Get all the fields in a JSON object."
  [(fields json)])

(documentation: /.field
  "A JSON object field getter."
  [(field key json)])

(documentation: /.has
  "A JSON object field setter."
  [(has key value json)])

(template [<name> <desc>]
  [(documentation: <name>
     (format "A JSON object field getter for " <desc> "."))]

  [/.boolean_field "booleans"]
  [/.number_field  "numbers"]
  [/.string_field  "strings"]
  [/.array_field   "arrays"]
  [/.object_field  "objects"]
  )

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            (format "Functionality for reading and writing values in the JSON format."
                    \n "For more information, please see: http://www.json.org/")
            [..json
             ..fields
             ..field
             ..has

             ..boolean_field
             ..number_field
             ..string_field
             ..array_field
             ..object_field
             
             ($.default /.Null)
             ($.default /.Boolean)
             ($.default /.Number)
             ($.default /.String)
             ($.default /.JSON)
             ($.default /.Array)
             ($.default /.Object)
             ($.default /.null?)
             ($.default /.object)
             ($.default /.equivalence)
             ($.default /.format)
             ($.default /.codec)]
            []))
