kyp0717
2021-6-6 11:27:17

Please help with json. I am trying to create a json object like so … (require json) (define a "hello") (write-json #hasheq((key1 . a))) ;; expected result {"key1": "hello"} ;; actual result .. {"key1": ; write-json: expected argument of type <legal JSON value>; given: 'a ; Context (plain; to see better errortrace context, re-run with C-u prefix): ; /usr/share/racket/collects/json/main.rkt:132:2 loop What am I doing wrong?


sorawee
2021-6-6 11:33:14

Try

(write-json #hasheq((key1 . "a")))


sorawee
2021-6-6 11:33:38

Oh, you want to make it "hello"


sorawee
2021-6-6 11:34:01

You can’t use #hasheq then. It constructs the hash literally


kyp0717
2021-6-6 11:34:22

I wanted "hello" .


sorawee
2021-6-6 11:34:29

Instead, use:

(write-json (hash 'key1 a))


kyp0717
2021-6-6 11:34:40

Ah…so I can’t use #hasheq .. OK!


sorawee
2021-6-6 11:34:48

This is like '(a) vs (list a)


sorawee
2021-6-6 11:35:21

kyp0717
2021-6-6 11:37:09

Thanks. I will review the article.


kyp0717
2021-6-6 11:37:57

How to generated this json object .. {"key1": “hello”, “key2”, “goodbye”} ?


kyp0717
2021-6-6 11:38:09

Can I do this …


kyp0717
2021-6-6 11:38:42

(write-json (hash ’key1 a ’key2 b)) ??


sorawee
2021-6-6 11:39:10

Yes, assuming that a is bound to "hello" and b is bound to "goodbye"


kyp0717
2021-6-6 11:40:26

yup…that works! thanks!


sschwarzer
2021-6-6 12:41:32

@mflatt This still fails. I entered a ticket: https://github.com/racket/racket-pkg-website/issues/76


ben.knoble
2021-6-6 13:13:36

Also `#hasheq((key . ,a)) (The unquote only works for the values, not they keys)


jorge.garcia.gonzalez
2021-6-6 23:57:27

@jorge.garcia.gonzalez has joined the channel