How to create a Motoko type which has a reserved word as a property identifier?

I am wanting to define a type with a structure like:

public type MyType = {
id : Text;
object : Text;
}

This doesn’t work due to the reserved word “object” in there.

My first intuitive workarounds don’t work either:

public type MyType = {
id : Text;
“object” : Text;
}

public type MyType = {
id : Text;
object : Text;
}

I can define the type in Candid by quoting the “object” - but there seems then no way to import that Candid file into my Motoko module as a type…

So what is the solution? I am integrating with an external API, so this structure MUST be created for my application to succeed…

I’ve search the documentation and even asked the AI for any clues, but to no avail…

Any ideas?

Not sure but I think you can refer to it via object_

@chenyan?

(On mobile so can’t double check)

1 Like

I thought you put a _ at the end. Not sure where I remember that from…some example with a property of type_.

1 Like

Yes, in the doc @claudio posted, you can see that field name object_ in Motoko maps to object in Candid.

1 Like

Thank you everyone for the solution!

1 Like