Open vintnes opened 1 year ago
hi @vintnes ! Yes, it's definitely a little bit more painful. I added define-json-type
to be able to define simple JSON objects in a very simple way, but when it comes to flexibility you run into the issue you are having now. It might be worth adding keyword arguments there as you suggest, for example:
(define-json-type <manifest>
(initialization-date "initializationDate")
(product)
(train-number "trainNumber" #:encode number->string #:decode string->number)
(service-id "serviceId")
(wagons "wagons" #(<wagon>)))
I don't have much time lately but I think it would be a nice addition. I'll see if I find some time soon.
Hi Aleix. Thank you for this solid library I use daily.
It's kind of painful when a JSON type with a nested record type needs to implement some value conversion.
Example
Now let's say we'd like to operate on the train number (simpler than the date for illustration purposes), delivered to us by the grace of German engineering in string format. Reformatting according to
define-json-mapping
is a little tedious but overall worth the convenience/granularity tradeoff in my opinion. The painful part is that we also have to manually map any nested records, which isn't related to the problem we're working on.Am I just missing something simple? Is there any reason why
define-json-type
can't support thescm->value
andvalue->scm
field specifications? Have you considered using keywords over positional parameters, or would you be open to that change in the future? Thanks again for your support.