typescript-json-serializer is a TypeScript library designed to facilitate the conversion between JavaScript/JSON objects and strongly-typed TypeScript classes. It leverages TypeScript decorators (`@JsonObject`, `@JsonProperty`) to define the serialization and deserialization mapping, allowing for complex nested structures, inheritance, and custom property transformations. The current stable version is 6.0.1, with a consistent release cadence that includes multiple major versions (v4, v5, v6) over a short period, indicating active maintenance and ongoing development. Its key differentiator lies in its declarative, decorator-driven approach, which provides a robust way to manage serialization logic directly within class definitions, including explicit support for enums, dates, and custom type resolvers. It also offers flexible configuration options for error handling, nullish value policies, and property name formatting, distinguishing it from simpler `JSON.parse`/`JSON.stringify` methods or libraries that rely purely on reflection without explicit decorator metadata.
npm install typescript-json-serializerVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining classes with `JsonObject` and `JsonProperty` decorators, instantiating `JsonSerializer`, and performing both deserialization from a JSON payload to a TypeScript class instance and serialization back to JSON.
Consult the official GitHub repository's release notes for the specific version you are upgrading to and adjust your code accordingly.
Add or ensure the following entries in your `tsconfig.json`:
```json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
}
```For nested objects, ensure `@JsonProperty({type: MyNestedClass})` is used. For arrays, use `@JsonProperty({type: () => MyArrayElementClass})` for proper type inference and deserialization.Ensure `emitDecoratorMetadata` and `experimentalDecorators` are set to `true` in your `tsconfig.json` file.
Verify that all classes intended for serialization are decorated with `@JsonObject()` and all properties needing to be serialized/deserialized have the `@JsonProperty()` decorator. Check `name` mappings if the JSON key differs from the class property name.
Ensure that the incoming JSON data contains all properties marked as `required: true`. Alternatively, adjust the `required` setting in `@JsonProperty` if the property is not strictly mandatory.
No dependency data recorded yet.