Your domain model is not JSON. It does not have to be.
@GiulioCanti3.5K followers
19,126 views
10 Comments
Comments from the original post on X (Twitter)

@thefubhy
It's weird that there is a Schema.Graph but not Schema.Cron
11 likes

@teej_dv
is there a way to avoid calling json.parse in the examples? i can't remember what the "right" way is to do that there
5 likes

@GiulioCanti
Yes, you can compose it with Schema.fromJsonString const jsonStringCodec = Schema.fromJsonString( Schema.toCodecJson(WalletSnapshot) ) The same codec also encodes directly to a JSON string. I kept JSON.parse explicit only to distinguish JSON text from JSON safe data
10 likes

@teej_dv
got it, that was the one i think i was missing. ty ty
2 likes

@theopomies
One day we'll have fullstack Effect and this will be one of the pillars
3 likes

@iSnifer
There are plenty methods that use it under the hood, so you don't need to call it manually: HttpBody.jsonSchema, HttpClientRequest.schemaBodyJson, HttpClientResponse.schemaJson, HttpClientResponse.schemaBodyJson, HttpServerRequest.schemaBodyJson, HttpServerResponse.schemaJson, HttpIncomingMessage.schemaBodyJson, etc
2 likes

@andreafspeziale
Somehow recalls me the old good days of io-ts
1 like

@buswe_com
Keeping the codec at the edge lets your domain model hold rich types like Date, bigint or branded ids and only flatten to JSON on the wire.

@patroza
The one time it’s kind of a downside is when you have a document database query engine where you’re expected to pass in json values; as json codecs are untyped. Encoded in v3 worked well there. Then again, we can of course build the query api as Type or Encoded, and then use the json codec internally to translate

@anderslie
literal godsend. how does it handle optional / make sure no undefined is in the serialized form? current pain is defining Schema.optionalWith(..., { exact: true, as: "Option" }) everywhere to make sure undefined is omitted from keys entirely