Skip to content

nullable fields in define-json-type macro #87

@ebeem

Description

@ebeem

Thanks for the awesome work.
I was wondering if it's possible to somehow allow nullable fields in the define-json-type macro.
I think that this is indeed the expected behavior.

Example

(define-json-type <student>
  (id)
  (name)
  (major "major" <major>))

(define-json-type <major>
  (id)
  (name)
  (parent "parent" <major>))

(define json-str "{ \"id\": 1, \"name\": null, \"major\": null}")
(json->student json-str)

error

In procedure assoc: Wrong type argument in position 2 (expecting association list): null

changing the json-str to the below

builds a correct (not unspecified) scheme object

(define json-str "{ \"id\": 1, \"name\": null, \"major\": {}}")
(json->student json-str)

output

=> #<<student> id: 1 name: null major: #<<major> id: #<unspecified> name: #<unspecified> parent: #<unspecified>>>

also emitting the field major will produce correct results.

(define json-str "{ \"id\": 1, \"name\": null }")
(json->student json-str)

output

=> #<<student> id: 1 name: null major: #<unspecified>>

Anything wrong with my approach?
Thanks again for your great work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions