A Swift framework for converting model objects (classes and structs) to and from JSON.
ObjectMapper is a Swift framework designed to map JSON data to and from Swift model objects (classes and structs). It solves the problem of manual JSON parsing by providing a declarative, type-safe way to define how JSON keys correspond to object properties, streamlining data serialization and deserialization in iOS and macOS apps.
Swift developers building iOS, macOS, or server-side applications who need a robust, flexible solution for converting JSON API responses into native Swift objects.
Developers choose ObjectMapper for its simplicity, support for complex nested structures, custom transformations, and compatibility with immutable models. It offers a more granular and customizable approach than Swift's built-in `Codable` for advanced mapping scenarios.
Simple JSON Object mapping written in 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.
Uses the `<-` operator for clear, type-safe property mapping, eliminating manual JSON parsing and reducing boilerplate code, as shown in the basic User class example.
Supports custom transforms like DateTransform, allowing easy conversion between JSON strings and Swift types such as Date objects, with the ability to create custom transforms via TransformType.
Through the ImmutableMappable protocol, it enables thread-safe models with immutable properties, using `try` for initialization and `>>>` for serialization, as detailed in the comparison table.
Dot notation for accessing nested keys simplifies mapping complex JSON structures, such as 'distance.value', and supports arrays and custom delimiters for edge cases.
Each model must implement init?(map: Map) and mapping(map: Map), which can be tedious and error-prone for large codebases compared to Codable's automatic synthesis.
ImmutableMappable requires using `try` in init and careful handling of optional properties, adding cognitive load that isn't as streamlined as Codable's throwing initializers.
Unlike Swift's built-in Codable, ObjectMapper is an external library, adding maintenance burden, potential versioning issues, and integration steps for package managers.