Effect CommunityEC
Effect Community2y ago
8 replies
Karl

Decoding and Encoding Data Structures with @effect/schema

Hi, is it possible to decode an unknown info a different structure? For example, I am getting some data in the form
// Unknown
const someVar = { id: 1, attributes: { first: "Foo", last: "Bar" } }


I want to decode this in such a way that
const result = Schema.decodeUnknownSync(MySchema)(someVar)
console.log(result) // should be { id: 1, first: "Foo", last: "Bar" }


And possible encode back to the original format to send to server. Can I achieve this through @effect/schema?
Was this page helpful?