Skip to content

Add read-only JSON aliases for record fields - #14

Merged
koehlma merged 1 commit into
mainfrom
work/agents/json-field-alias
Nov 6, 2026
Merged

koehlma merged 1 commit into
mainfrom
work/agents/json-field-alias

Conversation

@koehlma

@koehlma koehlma commented Nov 6, 2026

Copy link
Copy Markdown
Member

Record fields can now declare old JSON keys that are accepted when reading:

record Thread {
    #[json(alias("chatId", "conversationId"))]
    thread_id: string,
}

Rust and Python read threadId, chatId, or conversationId and write only threadId. Aliases also work when the record is inlined or used as a variant payload, and several alias(...) attributes on one field accumulate. TypeScript types and checks, JSON Schema, and OpenAPI keep only the main name.

Rationale

Isolade renamed chats to threads. Some of its records are stored as JSON and also served through its API. Without aliases, renaming such a field means either keeping the old key forever or migrating stored data. With an alias, the field gets its new name and old data keeps loading.

Behavior

  • An input that contains more than one spelling of the same field, such as threadId and chatId, is rejected as a duplicate field.
  • Strict decoding treats aliases as known keys.
  • Schema checks reject an alias that repeats the field's name or another alias, collides with another field or alias in the flattened object (including inlined records and internal variant tags), or is placed on an inline field.
  • Only record fields support aliases. Variant case names do not.

Validation

Workspace Rust tests (including native and Serde round trips through the new aliases schema), Python tests, TypeScript runtime tests, Clippy, formatting, and the documentation build pass.

Risk Assessment

Blast Radius: Minor

The feature is opt-in. Schemas without aliases decode and encode exactly as before. A bug would affect only fields that declare aliases.

Reversibility: Easy

Users who haven't adopted aliases are unaffected by a revert. Schemas that use aliases would need to drop them.

Created on behalf of @koehlma by Claude Code / claude-opus-5-5 · Task

@koehlma koehlma mentioned this pull request Nov 6, 2026
@koehlma
koehlma added this pull request to stack #16 November 6, 2026 17:11
@koehlma
koehlma merged commit fcf69b8 into main Nov 6, 2026
12 checks passed
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