Skip to content

Instantly share code, notes, and snippets.

@einarwh
einarwh / from-x-to-y.txt
Created November 18, 2026 11:28
From X to Y
From 3000ms to 300ms
From Analytics to Action
From Audience to Authority
From Basics to Beyond
From Chaos to Compliance
From Chaos to Consistency
From Chatbot to Coworker
From Code to Compass
From Copilot to Co-Engineer
From Developer to DevRel
namespace FluentLogs;
public static class Check
{
public static InMemoryLoggerChainAssert<T> That<T>(InMemoryLogger<T> logger)
{
return new InMemoryLoggerChainAssert<T>(logger);
}
public class CustomerBlobJsonConverter : JsonConverter<CustomerDto20260303>
{
public override CustomerDto20260303 Read(
ref Utf8JsonReader reader,
Type typeToConvert,
JsonSerializerOptions options)
{
var root = JsonSerializer.Deserialize<JsonElement>(ref reader);
var schema = root.GetProperty("$schema").GetString();
return schema switch
@einarwh
einarwh / customer-schema-20260101.json
Created April 8, 2026 10:15
Customer Schema (first version), published 01.01.2026.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/hellish-enterprise/customer-schema-20260101.json",
"title": "Customer",
"description": "Validation schema for customers.",
"type": "object",
"required": ["userId", "email", "birthDate"],
"properties": {
"userId": {
"type": "string",
@einarwh
einarwh / customer-schema-20260202.json
Created April 8, 2026 10:13
Customer Schema (second version), published 02.02.2026. Changed type of 'birthDate' from datetime to date. Added 'displayName'.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/hellish-enterprise/customer-schema-20260202.json",
"title": "Customer",
"description": "Validation schema for customers.",
"type": "object",
"required": ["userId", "email", "birthDate", "displayName"],
"properties": {
"userId": {
"type": "string",
@einarwh
einarwh / customer-schema-20260303.json
Last active April 8, 2026 10:07
Customer Schema (third version), published 03.03.2026. Renamed 'userId' to 'userName' and added 'items' property.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/hellish-enterprise/customer-schema-20260303.json",
"title": "Customer",
"description": "Validation schema for customers.",
"type": "object",
"required": ["userName", "email", "birthDate", "displayName", "items"],
"properties": {
"userName": {
"type": "string",
@einarwh
einarwh / JsonMorgue.linq
Last active April 8, 2026 10:00
Life in the JSON morgue.
void Main()
{
var john1 = new CustomerDto20260101
{
UserId = "john-1",
Email = "john.fst@foomail.com",
BirthDate = new DateTime(2001, 01, 01),
};
var john2 = new CustomerDto20260202
@einarwh
einarwh / Serialize.cs
Created March 20, 2026 13:56
Serialization with validation.
public string Serialize(Customer customer, string schemaName, JsonSchema schema)
{
var jsonDoc = JsonSerializer.SerializeToDocument(customer, GetSerializerOptions());
var evaluation = schema.Evaluate(jsonDoc.RootElement, GetEvaluationOptions());
var assembly = Assembly.GetAssembly(typeof(JsonSchema));
var fileVersion =
assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>()?
.Version;
var validatorName = $"{assembly.GetName().Name}-{fileVersion}";
@einarwh
einarwh / pellegriff.json
Last active March 17, 2026 14:16
Valid cat
{
"name": "Pellegriff",
"age": 1,
"miceCaught": 0,
"espressosSpilled": 2,
"$schema": "/cat/schema-20260310.json",
"$validation": {
"tool": "JsonSchema.Net-9.1.3",
"timestamp": "2026-03-17T07:52:34.837129Z",
"result": true
@einarwh
einarwh / toValidatedJson.fs
Created March 16, 2026 12:25
Tagging JSON with schema.
let toValidatedJson (schemaText: string) (schemaName: string) (o: obj) =
let jsonDoc = JsonSerializer.SerializeToDocument(o, serializerOptions)
let schema = JsonSchema.FromText(schemaText)
let evalOptions = EvaluationOptions()
evalOptions.OutputFormat <- OutputFormat.Flag
evalOptions.RequireFormatValidation <- true
let results = schema.Evaluate(jsonDoc.RootElement, evalOptions)
if results.IsValid then
let jsonObj = JsonObject.Create(jsonDoc.RootElement)