Add typed/json which exports almost all of json

Does not include support for custom nulls, but is otherwise entirely
functional.

Closes #3.
This commit is contained in:
Alexis King 2014-12-20 19:54:52 -08:00 committed by Sam Tobin-Hochstadt
parent ca88457092
commit 9fe834d35c
2 changed files with 20 additions and 0 deletions

View File

@ -78,6 +78,7 @@ The following libraries are included with Typed Racket in the
@defmodule/incl[typed/rackunit]
@defmodule/incl[typed/srfi/14]
@defmodule/incl[typed/syntax/stx]
@defmodule/incl[typed/json]
Other libraries included in the main distribution that are either
written in Typed Racket or have adapter modules that are typed:

View File

@ -0,0 +1,19 @@
#lang typed/racket/base
;; a typed wrapper for the json library
(provide JSExpr)
(define-type JSExpr
(U 'null Boolean String Integer Inexact-Real (Listof JSExpr) (HashTable Symbol JSExpr)))
(require/typed/provide json
[jsexpr? (Any -> Boolean)]
[write-json (->* (JSExpr)
(Output-Port #:encode (U 'control 'all))
Any)]
[read-json (->* () (Input-Port) (U JSExpr EOF))]
[jsexpr->string (JSExpr [#:encode (U 'control 'all)] -> String)]
[jsexpr->bytes (JSExpr [#:encode (U 'control 'all)] -> Bytes)]
[string->jsexpr (String -> JSExpr)]
[bytes->jsexpr (Bytes -> JSExpr)])