Skip to content
Arnel Robles edited this page Sep 28, 2026 · 1 revision

Package 9: Mapsicle.Json

Map and serialize in one call, with System.Text.Json.

using Mapsicle.Json;

// Map to UserDto, then serialize the DTO
string? json = user.MapToJson<UserDto>();

// Deserialize to the type the JSON describes, then map that to the destination
UserDto? dto = json.MapFromJson<User, UserDto>();

// Collections
string? arrayJson = users.MapCollectionToJson<UserDto>();
List<UserDto> dtos = arrayJson.MapCollectionFromJson<User, UserDto>();

MapFromJson takes two type arguments: the first is what the JSON deserializes into, the second is what that gets mapped to. There are also MapToJsonBytes, MapToJsonAsync, MapFromJsonAsync, MapFromJsonBytes, MapFromJsonDocument and MapFromJsonElement, and an IMapper overload for the fluent path. Every method takes optional JsonSerializerOptions; JsonMappingOptions has presets for camelCase, snake_case, kebab-case, indented and strict.


Clone this wiki locally