SWON: Swift Macros for Foundation-Free JSON Processing

SWON is a lightweight Swift tool created to make JSON decoding available in a Swift project that doesn’t support Foundation. 

Before SWON, developers relied on Foundation and Codable to generate JSON decoding code. Now, SWON makes it possible by using Swift macros that perform this operation at compile time. 

Together with making developers parse JSON without using a heavy system framework, SWON helps systems-level Swift or command-line tools to optimize performance. Plus, creating the decoding code at compile time enables developers to catch errors early, not at runtime.

The tool is open source and free to use by developers of all levels.

Key Features

  • Generate JSON decoding codes
  • Swift macros
  • Catches errors early

Pros & Cons

ProsCons
Developers can parse JSON without relying on Foundation-based tools like Codable and JSONDecoder. This especially comes in handy when working with a project where Foundation is unavailable.It does not support dictionary keys that are enums or integers.
‎In some server-side setups where Codable is unsupported, SWON can still generate JSON  decoding codes.It requires every element in an array to be valid and non-optional.
‎It makes decoding JSON efficient by operating at compile time. Together with making the process faster, it ensures it outputs type-safe data types and detects any errors before runtime.
It avoids implicitly synthesized code and uses init(fromJSON:) to decode JSON. This can help developers manage and debug the flow of their code.

Pricing & Plans

SWON is open-source and free to use by any developer. It is released under the permissive MIT license.

Conclusion

SWON is the go-to JSON decoding tool to go beyond Swift’s standard limitation to JSON decoding. 

It stands out by removing the barrier of Foundation dependency and replacing it with a Swift macro that generates JSON decoding code at compile time. Plus, constrained environments where binary size and dependency control matter will not need to pull in a system framework to parse JSON. 

It may only support strings for its dictionary keys, but it is open-source and free to use for developers who want to use it for personal or commercial use.