Here is a very simple example:
(require json) (define x (string->jsexpr "{\"foo\": \"bar\", \"bar\": \"baz\"}")) (for (((key val) (in-hash x))) (printf "~a = ~a~%" key val))
Here you can use it with a JSON based API:
(require net/http-client json) (define-values (status header response) (http-sendrecv "httpbin.org" "/ip" #:ssl? 'tls)) (define data (read-json response)) (printf "My IP address is ~a~%" (hash-ref data 'origin))
In the OP request here, you can create a JSON value from a structure type:
(require json) (struct person (first-name last-name age country)) (define (person->jsexpr p) (hasheq 'first-name (person-first-name p) 'last-name (person-last-name p) 'age (person-age p) 'country (person-country p))) (define cky (person "Chris" "Jester-Young" 33 "New Zealand")) (jsexpr->string (person->jsexpr cky))
source share