Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

keeshux/swon

Repository files navigation

SWON

Foundation-free Swift/JSON processing.

SWON is a tiny set of Swift Macros that extend value types with simplified JSON processing without the need for Codable or the Foundation framework.

SWON should work on every supported Swift platform. Tested on Apple, Android, Linux, and Windows.

Usage

Dead easy. Attach the macro to any struct or enum:

import SWON
@SWON
enum Color {
	case red, green, blue
}
@SWON
struct Foobar {
	let numField: Int
	let stringArray: [String]
	let myDictionary: [String: [Double]]
	let innerStructs: [[CustomStruct]]
	let namedList: [Color]?
}

And you'll get a new initializer:

let foobar = try Foobar(fromJSON: """
{
"numField": 100,
"stringArray": ["one", "two", "three"]
	...
}
""")

Why?

SWON is part of an ongoing "fight" against Swift dependencies outside of the Apple ecosystem, whose goal is making my app, Passepartout, natively cross-platform with Swift.

If you only use Swift on Apple platforms, you won't find this package very useful, if at all. JSONEncoder and JSONDecoder offer such a thorough feature set that SWON doesn't even try to replace them.

Instead, it serves the single purpose of parsing complex value types with a tiny footprint, because it doesn't rely on Foundation. In fact, SWON doesn't even use Codable, thus making it a future candidate for Embedded Swift, where Codable is unavailable.

Last but not least, it was an entertaining exercise to get familiar with Swift Macros.

SWON uses the amazingly written cJSON parser (C) under the hood.

Caveats

Restrictions

  • Dictionary keys must be String.
  • Optionals in collections (e.g. [Int?]) are not supported.

Things to do

  • Encode Swift to JSON (decode-only for now).
  • Enums with associated types.
  • Do not suppress errors inside an optional field (silently made nil).

License

Copyright (c) 2025 Davide De Rosa. All rights reserved.

This project is licensed under the MIT.

Contacts

Twitter: @keeshux

Website: davidederosa.com, with my blog series on cross-platform Swift.

About

Swift Macros for Foundation-free JSON processing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /