Add toJSON() to Struct and document architectural trade-offs#9
Draft
Add toJSON() to Struct and document architectural trade-offs#9
Conversation
- Add toJSON() method to Struct so JSON.stringify works out of the box - Add ARCHITECTURE.md documenting property descriptors vs proxies trade-offs - Update README gotcha about JSON.stringify now working - Add 3 tests for toJSON (primitives, substructs, empty struct) - Update CHANGELOG with 0.17.0 entry Agent-Logs-Url: https://github.com/rotu/structview/sessions/31ab83a8-abbb-4e43-9fe6-13b54ee4f3ae Co-authored-by: rotu <119948+rotu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Reconsider architectural foundations of structview library
Add toJSON() to Struct and document architectural trade-offs
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Architectural review of property descriptors vs proxies vs instance descriptors, with a concrete fix for the main ergonomic gap.
Analysis (
ARCHITECTURE.md)Prototype property descriptors remain the right call. Proxies would fix spread/JSON ergonomics but cost 5–10× on property access, break TypeScript inference, and don't compose with
class/instanceof. Instance descriptors would fix spread but add per-instance GC pressure—bad for large struct arrays.toJSON()onStructThe biggest practical gap:
JSON.stringify(struct)returned{}because it only sees own enumerable properties.toJSON()iterates inherited enumerable fields into a plain object. Nested substructs serialize recursively via the standardtoJSONprotocol.core.ts—toJSON()method onStructmod_test.ts— 3 tests: primitive fields, nested substructs, empty structREADME.md— Updated gotcha Add toJSON, structToObject, pad, and enumField to structview #4 (JSON.stringify now works; spread still needss.toJSON())CHANGELOG.md— 0.17.0 entry