Open ebeem opened 1 month ago
I could solve it by modifying the extract-field
macro to check for null values in addition to the pair check
(let-syntax ((extract-field (syntax-rules ()
((_ table (field key scm->value value->scm))
(scm->value (if (and (pair? (assoc key table)) (not (equal? 'null (cdr (assoc key table)))))
(cdr (assoc key table)) *unspecified*)))
((_ table (field key scm->value))
(scm->value (if (pair? (assoc key table)) (cdr (assoc key table)) *unspecified*)))
((_ table (field key))
(if (pair? (assoc key table)) (cdr (assoc key table)) *unspecified*))
((_ table (field))
(if (pair? (assoc (symbol->string 'field) table)) (cdr (assoc (symbol->string 'field) table)) *unspecified*)))))
(ctor (extract-field table spec) ...))
;; before
(scm->value (if (pair? (assoc key table)) (cdr (assoc key table)) *unspecified*))
;; after
(scm->value (if (and (pair? (assoc key table)) (not (equal? 'null (cdr (assoc key table)))))
(cdr (assoc key table)) *unspecified*))
Thanks for the awesome work. I was wondering if it's possible to somehow allow
nullable
fields in thedefine-json-type
macro. I think that this is indeed the expected behavior.Example
error
changing the json-str to the below
builds a correct (not unspecified) scheme object
output
also emitting the field major will produce correct results.
output
Anything wrong with my approach? Thanks again for your great work.