Skip to content

Decoding JSON fields with multiple value types #45

Open
@azuzunaga

Description

@azuzunaga

I'm trying to decode a JSON field that can have values of Int or String. Unfortunately I don't have a way to change the serialization. Following the docs it looks like the approach for things like this is creating a sum type and then using variants to decode/encode.

However, I've been having trouble getting the right result. I've tried using variantMatch and variantCase, but both expect a tagged object.

Here is a minimally reproducible example using variantCase. What is the best approach to handle JSON fields with mixed value types?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions