A simple Swift library for converting JSON to strongly typed objects with immutable properties.
Mapper is a JSON deserialization library for Swift that converts JSON data into strongly typed Swift objects. It solves the problem of safely and predictably parsing JSON responses from APIs by enforcing type safety and supporting immutable properties. The library provides a clean, protocol-oriented API that integrates naturally with Swift's type system.
Swift developers building iOS, macOS, or server-side applications that consume JSON APIs and need reliable, type-safe data parsing. Particularly useful for developers who prefer immutable data models and want to avoid runtime JSON parsing errors.
Developers choose Mapper for its simplicity, strong emphasis on type safety, and support for immutable properties—features not always available in other JSON libraries. Its lightweight API and seamless integration with Swift's type system make it a pragmatic choice for projects where predictable JSON deserialization is critical.
A JSON deserialization library for Swift
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Mapper enforces immutable properties using let declarations in Mappable objects, ensuring thread-safe and predictable state, as shown in the User struct example where id and photoURL are immutable.
It converts JSON to strongly typed Swift objects with error-throwing for missing fields, reducing runtime crashes; for instance, the init method uses try for required fields like id.
Supports custom transformations for complex JSON structures, such as extracting a first name from a full string via transformation functions, allowing handling of non-standard formats.
Integrates with Swift enums through the Convertible protocol or raw values, enabling type-safe mapping of JSON to enum cases, as demonstrated with UserType mapping from a string.
Since Swift 4 introduced the native Codable protocol, Mapper adds unnecessary complexity and boilerplate for projects that could use built-in, automatically synthesized parsing with less code.
The README lists open radars from 2015-2016 related to Swift language limitations, suggesting the library may be outdated or inactive, with possible compatibility issues in newer Swift versions.
Requires implementing the Mappable protocol with custom initializers for each type, which can be more verbose and error-prone compared to Codable's minimal or automatic conformance.