Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Latest commit

 

History

History
21 lines (14 loc) · 650 Bytes

File metadata and controls

21 lines (14 loc) · 650 Bytes

Encoding Objects

Since we can decode objects we need to have a way to encode them into JavaScript objects as well. The encode expression is the way to do that:

encode { name = "Bob" } /* Object */
encode variable /* Object */

The encode expression tries to encode a typed object into a JavaScript object (Object type in Mint), in case that it's impossible to do that you will get a nice error message.

The general rule is that you can encode everything which can be decodeed.

Encoding data is useful when you want to convert it to Json:

encode { name = "Bob" }
|> Json.stringify()
/* { "name": "Bob"} */