Make JSON encoding of DAML-LF variants easier to pattern match on #3622
Closed
Description
Currently, values of DAML-LF variant types like
variant Foo =
| Bar Int
| Baz Foo.Baz
record Foo.Baz = {baz : Text}
get encoded to JSON values like
{ "Bar": 5 }
{ "Baz": {"baz": "text"} }
"Pattern matching" on this representation in JavaScript/TypeScript is a bit inconvenient since you have to build a chain of if
-statements and add a final unreachable else
branch.
I suggest we rather follow the approach described in the TypeScript handbook, i.e., represent the same values as
{ "type": "Bar", "data": "Int" }
{ "type": "Baz", "data": {"baz": "text"} }
I'm also open to inlining the record in the second case, i.e.
{ "type": "Baz", "baz": "text" }
but I don't care too much.