-
Notifications
You must be signed in to change notification settings - Fork 1
Json
Arnel Robles edited this page Sep 28, 2026
·
1 revision
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.
Mapsicle
Packages
- Core
- Fluent
- EntityFramework
- Validation
- NamingConventions
- Serilog
- Dapper
- AspNetCore
- Json
- Caching
- Audit
- DataAnnotations
Reference