Skip to content

http: serialize event details like ASP.NET Core JSON responses - #111

Merged
rameel merged 3 commits into
mainfrom
http/web-json-event-details
Oct 28, 2026
Merged

rameel merged 3 commits into
mainfrom
http/web-json-event-details

Conversation

@rameel

@rameel rameel commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Event details passed to TriggerEvent as an object were serialized with the 1.x options:
dictionary keys were camel-cased and null properties were dropped. Dictionary keys are data,
so Errors["Email"] reached the browser as email, and the JSON differed from the
JsonTypeInfo example in the docs.

  • The object overload now uses JsonSerializerDefaults.Web, as ASP.NET Core does for JSON
    responses: property names are camel-cased, while dictionary keys and null values are written
    as is. The migration guide lists this as a silent change.
  • New TriggerEvent(string, object, JsonSerializerOptions, HtmxTriggerTiming) overload, similar to
    Results.Json(object, JsonSerializerOptions), for details that must follow the application's JSON
    options. On .NET 6 it is the only way to do that, because JsonSerializerOptions.GetTypeInfo
    is not public there.
  • All overloads write the detail through one writer, so the header stays compact, and non-ASCII
    characters in string values and dictionary keys are escaped whatever the options say.

The object overload of TriggerEvent still used the 1.x options: it
camel-cased dictionary keys and dropped null properties. Keys are data,
such as field names, so Errors["Email"] reached the browser as "email"
and "Address.City" as "address.City". The JSON also differed from the
JsonTypeInfo example in the docs, which says the payload stays the same.

Use JsonSerializerDefaults.Web, which ASP.NET Core uses for JSON
responses by default: property names are camel-cased, while dictionary
keys and null values are written as is.
Add TriggerEvent(string, object, JsonSerializerOptions, timing). All
overloads now write the detail through the same writer, so the header
stays compact and escapes non-ASCII characters in string values and
dictionary keys whatever the options say.
@rameel
rameel merged commit 9e80e38 into main Oct 28, 2026
1 check passed
@rameel
rameel deleted the http/web-json-event-details branch October 28, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant