aeson icon indicating copy to clipboard operation
aeson copied to clipboard

Add a SumEncoding option that's somewhere between a TaggedObject and an UntaggedValue

Open poscat0x04 opened this issue 4 years ago • 1 comments

Sometimes the tag and the content of the JSON you're processing are on the same level where both TaggedObject and UntaggedValue will not suffice. I propose adding another SumEncoding option that handles this case. The implementation should be very similar to that of UntaggedValue.

poscat0x04 avatar Jan 17 '21 04:01 poscat0x04

Hmmm, this is tricky to implement for constructors that do not have field names. We cannot drop them cause then we will lose the roundtrip property. Maybe we should use the position as the key when encoding and decoding. For example, A 1 1 should be encoded to

{
  "tag": "A",
  "1" : 1,
  "2": 1
}

where A is defined as

data A = A Int Int | B Int Int

poscat0x04 avatar Jan 17 '21 09:01 poscat0x04