Decoding really "flexible" JSON schema?

:100: Strongly agree with @jacob . It’s much easier to figure out decoders once you’ve defined the problem as “I have this JSON and I want to decode it into this type”

In this situation, you’ll have to resolve a lot of the ambiguity just to design types that capture the information you need. Is everything going to be stored in some super-generic tree or graph structure? Perhaps you want to force everything into one of n predefined record shapes? Something else altogether?

:point_up: designing these types is the hardest part. Once you have these it makes figuring the decoders much more straightforward. Generally some combination of andThen and oneOf (with a bit of keyValuePairs thrown in if you need the names of keys)

2 Likes