class-transformer is a TypeScript library that converts plain JavaScript objects into typed class instances and back, using decorators to define transformation rules. It serves as a decorator-based object transformer, JSON deserialization library, and property transformation framework, enabling type-safe serialization and deserialization of class instances.
The library distinguishes itself through comprehensive property filtering and mapping capabilities. It supports excluding properties by default, by prefix, by operation (serialization or deserialization), or by explicit marking, as well as filtering properties by group or version range. Property renaming, stripping extraneous properties, and exposing computed properties from getters or methods are also supported, giving fine-grained control over transformation output.
Beyond basic conversion, class-transformer handles nested object transformation, automatic type conversion to match TypeScript-declared types, and polymorphic type discrimination using discriminator properties. It can transform array and collection elements, apply custom transformation logic, convert date strings to Date objects, and handle method return values. The library also provides deep cloning of class instances and direct serialization to and deserialization from JSON strings.
Documentation covers decorator usage, transformation options, and configuration for all supported features, with examples demonstrating each capability.