Add to/from bytes functions to the json library.
Also add a distribution specs line.
This commit is contained in:
parent
818e434c60
commit
9d239170cf
|
@ -68,6 +68,13 @@ the @rfc for more information about JSON.
|
||||||
string?]{
|
string?]{
|
||||||
Generates a JSON source string for the @tech{jsexpr} @racket[x].}
|
Generates a JSON source string for the @tech{jsexpr} @racket[x].}
|
||||||
|
|
||||||
|
@defproc[(jsexpr->bytes [x jsexpr?]
|
||||||
|
[#:null jsnull any? (json-null)]
|
||||||
|
[#:encode encode (or/c 'control 'all) 'control])
|
||||||
|
bytes?]{
|
||||||
|
Generates a JSON source byte string for the @tech{jsexpr} @racket[x].
|
||||||
|
(The byte string is encoded in UTF-8.)}
|
||||||
|
|
||||||
@section{Parsing JSON Text into JS-Expressions}
|
@section{Parsing JSON Text into JS-Expressions}
|
||||||
|
|
||||||
@defproc[(read-json [in input-port? (current-input-port)]
|
@defproc[(read-json [in input-port? (current-input-port)]
|
||||||
|
@ -80,6 +87,10 @@ the @rfc for more information about JSON.
|
||||||
jsexpr?]{
|
jsexpr?]{
|
||||||
Parses the JSON string @racket[str] as an immutable @tech{jsexpr}.}
|
Parses the JSON string @racket[str] as an immutable @tech{jsexpr}.}
|
||||||
|
|
||||||
|
@defproc[(bytes->jsexpr [str bytes?] [#:null jsnull any? (json-null)])
|
||||||
|
jsexpr?]{
|
||||||
|
Parses the JSON bytes string @racket[str] as an immutable @tech{jsexpr}.}
|
||||||
|
|
||||||
@section{A word about design}
|
@section{A word about design}
|
||||||
|
|
||||||
JSON syntactically distinguishes ``@tt{null}'', array literals, and
|
JSON syntactically distinguishes ``@tt{null}'', array literals, and
|
||||||
|
|
|
@ -178,12 +178,20 @@
|
||||||
;; ----------------------------------------------------------------------------
|
;; ----------------------------------------------------------------------------
|
||||||
;; Convenience functions
|
;; Convenience functions
|
||||||
|
|
||||||
(provide jsexpr->string)
|
(provide jsexpr->string jsexpr->bytes)
|
||||||
(define (jsexpr->string x #:null [jsnull (json-null)] #:encode [enc 'control])
|
(define (jsexpr->string x #:null [jsnull (json-null)] #:encode [enc 'control])
|
||||||
(define o (open-output-string))
|
(define o (open-output-string))
|
||||||
(write-json x o #:null jsnull #:encode enc)
|
(write-json x o #:null jsnull #:encode enc)
|
||||||
(get-output-string o))
|
(get-output-string o))
|
||||||
|
(define (jsexpr->bytes x #:null [jsnull (json-null)] #:encode [enc 'control])
|
||||||
|
(define o (open-output-bytes))
|
||||||
|
(write-json x o #:null jsnull #:encode enc)
|
||||||
|
(get-output-bytes o))
|
||||||
|
|
||||||
(provide string->jsexpr)
|
(provide string->jsexpr bytes->jsexpr)
|
||||||
(define (string->jsexpr str #:null [jsnull (json-null)])
|
(define (string->jsexpr str #:null [jsnull (json-null)])
|
||||||
|
(unless (string? str) (raise-type-error 'string->jsexpr "string" str))
|
||||||
(read-json (open-input-string str) #:null jsnull))
|
(read-json (open-input-string str) #:null jsnull))
|
||||||
|
(define (bytes->jsexpr str #:null [jsnull (json-null)])
|
||||||
|
(unless (bytes? str) (raise-type-error 'bytes->jsexpr "bytes" str))
|
||||||
|
(read-json (open-input-bytes str) #:null jsnull))
|
||||||
|
|
|
@ -534,6 +534,9 @@ mz-extras :+= (- (package: "xml/")
|
||||||
(cond* (not plt) => (srcfile: "*-{tool|snipclass}.rkt"
|
(cond* (not plt) => (srcfile: "*-{tool|snipclass}.rkt"
|
||||||
"xml.png")))
|
"xml.png")))
|
||||||
|
|
||||||
|
;; -------------------- json
|
||||||
|
mz-extras :+= (package: "json/")
|
||||||
|
|
||||||
;; -------------------- ffi
|
;; -------------------- ffi
|
||||||
mz-extras :+= (collects: "ffi/") (doc: "objc")
|
mz-extras :+= (collects: "ffi/") (doc: "objc")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user