(define sample (dat:json-parse "{\"title\":\"dat \\\"thang\\\"\",\"items\":[true,false,null,-2,1.25e2],\"line\":\"a\\nb\"}")) (unless (equal? (dat:json-object-ref sample "title") "dat \"thang\"") (error 'test-failed "JSON strings and escaped quotes")) (unless (equal? (dat:json-object-ref sample "items") '(json:array #t #f json:null -2 125.0)) (error 'test-failed "JSON arrays, literals, and numbers")) (unless (equal? (dat:json-object-ref sample "line") "a\nb") (error 'test-failed "JSON escaped newline")) (unless (equal? (dat:json-parse "\"\\uD83D\\uDE00\"") (list->string (map integer->char '(#xf0 #x9f #x98 #x80)))) (error 'test-failed "JSON UTF-16 surrogate pair")) (unless (json:number-token? "-0.4E+3") (error 'test-failed "valid JSON number")) (when (json:number-token? "+1") (error 'test-failed "reject Scheme-only number spelling")) (let* ((wire '(json:object ("type" . "chat/text") ("content" . (json:object ("channel" . "general") ("text" . "hello\n🐬"))) ("timestamp" . 42))) (encoded (dat:json-stringify wire)) (decoded (dat:json-parse encoded))) (unless (equal? (dat:json-object-ref decoded "type") "chat/text") (error 'test-failed "S-expression JSON adapter object roundtrip")) (unless (equal? (dat:json-object-ref (dat:json-object-ref decoded "content") "text") "hello\n🐬") (error 'test-failed "S-expression JSON adapter escaped Unicode string"))) (let ((caught #f)) (catch #t (lambda () (dat:json-parse "[1,]")) (lambda args (set! caught #t))) (unless caught (error 'test-failed "reject trailing array comma"))) (display "S7 JSON/S-expression adapter: PASS\n")