Skip to content

Make JSON encoding of DAML-LF variants easier to pattern match on #3622

Closed
@hurryabit

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.

Metadata

Labels

component/json-apiHTTP JSON APIdiscussionThings to be discussed and decidedteam/ledger-clientsRelated to the Ledger Clients team's components.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions