Need help with json-typescript-mapper?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

130 Stars 53 Forks MIT License 32 Commits 37 Opened issues


a solution for adapter layer which make use of typescript reflection mapping from pure server-returned json to target typescript model

Services available


Need anything else?

Contributors list

# 354,591
17 commits



For single page application, data sources are obtained from API server. Instead of directly using api data, we definitely require an adapter layer to transform data as needed. Furthermore, the adapter inverse the the data dependency from API server(API Server is considered uncontrollable and highly unreliable as data structure may be edit by backend coder for some specific purposes)to our adapter which becomes reliable. Thus, this library is created as the adapter.

Get Started

npm install json-typescript-mapper --save


  • NodeJS
  • Browser


  • Typescript


import {deserialize} from 'json-typescript-mapper';

deserialize(, ); serialize();


Here is a complex example, hopefully could give you an idea of how to use it (for more on how to use, checkout /spec which are unit test cases):

class Student {

constructor() {
    this.fullName = undefined;


class Address { @JsonProperty('first-line') firstLine:string; @JsonProperty('second-line') secondLine:string; @JsonProperty({clazz: Student}) student:Student; city:string;

constructor() {
    this.firstLine = undefined;
    this.secondLine = undefined; = undefined;
    this.student = undefined


class Person { @JsonProperty('Name') name:string; @JsonProperty('xing') surname:string; age:number; @JsonProperty({clazz: Address, name: 'AddressArr'}) addressArr:Address[]; @JsonProperty({clazz: Address, name: 'Address'}) address:Address;

constructor() { = void 0;
    this.surname = void 0;
    this.age = void 0;
    this.addressArr = void 0;
    this.address = void 0;


Now here is what API server return, assume it is already parsed to JSON object.

let json = {
  "Name": "Mark",
  "xing": "Galea",
  "age": 30,
  "AddressArr": [
          "first-line": "Some where",
          "second-line": "Over Here",
          "city": "In This City",
          "student": {
              name1: "Ailun"
          "first-line": "Some where",
          "second-line": "Over Here",
          "city": "In This City",
          "student": {
              name1: "Ailun"
  "Address": {
      "first-line": "Some where",
      "second-line": "Over Here",
      "city": "In This City",
      "student": {
          name: "Ailun"

Simply, just map it use following code. The mapping is based on <@JsonProperty> decorator meta data.

const person = deserialize(Person, json);

If you want to reverse the action, from the other way round:

const json = serialize(person);


Remember to add: experimentalDecorators and emitDecoratorMetadata in your tsconfig.json. This is essential to enable decorator support for your typescript program. Example shown as followings:

  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  "exclude": [

Test Report

The test case will be covered in the next push. This caused by inconsistent return type. alt tag


1) Fixed test cases. According to typescript official website tips NULL IS BAD, therefore I updated all null value to void 0 which is a better expression than undefined (idea from underscore source code). Most cases it won't affect previous version at all.





json-typescript-mapper 1.1.1 - Added serialized function - Passed more unit tests

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.