Add JSONBridge example - #49
Open
MaxDesiatov wants to merge 2 commits into
Open
Conversation
Adds a `JSONBridge` example demonstrating how the result of JavaScript's `JSON.parse` maps onto a static Swift type via BridgeJS under Embedded Swift for WebAssembly. `Sources/JSONBridge/main.swift` declares a `@JSClass struct User` whose `@JSGetter` properties read typed fields, imports `globalThis.JSON.parse` statically as a `@JSClass(from: .global)` namespace, and exports `run()`, which parses three fixtures exercising present, `null`, and absent `nickname` values plus `Double` to `Int` narrowing. It depends on JavaScriptKit `0.54.1`, builds with the `PackageToJS` plugin via `swift package ... js --use-cdn`.
MaxDesiatov
commented
Jun 9, 2026
Co-authored-by: Max Desiatov <m_desiatov@apple.com>
Contributor
Author
|
@krodak this is not the final version and I'm curious how BridgeJS could be extended to make this more versatile, ideally we want to showcase de-serialization for multiple types here. Maybe |
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.
Added a
JSONBridgeexample demonstrating how the result of JavaScript'sJSON.parsemaps onto a Swift type via BridgeJS built with Embedded Swift for WebAssembly.Sources/JSONBridge/main.swiftdeclares a@JSClass struct Userwhose@JSGetterproperties read typed fields, importsglobalThis.JSON.parsestatically as a@JSClass(from: .global)namespace, and exportsrun(), which parses three fixtures exercising present,null, and absentnicknamevalues plusDoubletoIntnarrowing. It depends on JavaScriptKit0.54.1, builds with thePackageToJSplugin viaswift package ... js --use-cdn.