-
Notifications
You must be signed in to change notification settings - Fork 7
Closed
Description
Hi,
It seems that null
values in Json can't be parsed. Eg the following fails:
`
{
"errors": [
{
"extensions": {
"code": "unauthenticated",
"reference": null
},
"message": "You must be authenticated to perform this action",
"path": [ "startPlanCheckout" ]
}
]
}
`
->Js.Json.parseExn
->JsonCombinators.Json.decode(DecodeErrors.fetchResult)
My decoder is:
module DecodeErrors = {
open JsonCombinators.Json.Decode
type extensions = {
code: string,
reference: option<string>,
}
type error = {
message: string,
path: array<string>,
extensions: extensions,
}
type fetchResult = {errors: option<array<error>>}
let errorField = object(field => {
message: field.required(. "message", string),
path: field.required(. "path", array(string)),
extensions: field.required(.
"extensions",
object(field => {
code: field.required(. "code", string),
reference: field.optional(. "reference", string),
}),
),
})
let fetchResult = object(field => {
errors: field.optional(. "errors", array(errorField)),
})
}
This results in the following error: Expected string, got null\n\tat field 'reference'\n\ta…tensions'\n\tin array at index 0\n\tat field 'errors'
It seems that optional
doesnt support nulls (which makes sense since
Noneis compiled to
undefined` in Rescript).
Is there a way to make nulls
also be treated as optional?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels