diff --git a/typed-racket-doc/typed-racket/scribblings/reference/libraries.scrbl b/typed-racket-doc/typed-racket/scribblings/reference/libraries.scrbl index 7a08d3f9..af4d13ad 100644 --- a/typed-racket-doc/typed-racket/scribblings/reference/libraries.scrbl +++ b/typed-racket-doc/typed-racket/scribblings/reference/libraries.scrbl @@ -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: diff --git a/typed-racket-more/typed/json.rkt b/typed-racket-more/typed/json.rkt new file mode 100644 index 00000000..ea1a0ed2 --- /dev/null +++ b/typed-racket-more/typed/json.rkt @@ -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)])