@expeed/ngx-data-mapper

January 12, 2026 · View on GitHub

A visual drag-and-drop data mapping component for Angular applications. Create field mappings between source and target JSON schemas with transformations, array mapping, and default values.

Features

  • Drag & Drop Mapping: Visually connect source fields to target fields
  • Multi-Source Mapping: Combine multiple source fields into one target (concatenation)
  • Transformations: Apply data transformations (uppercase, lowercase, trim, date formatting, number formatting, substring, replace, mask, templating)
  • Array Mapping: Map array fields with optional filtering
  • Array-to-Object: Select single item from array using first, last, or conditional logic
  • Default Values: Set defaults for unmapped target fields
  • Endpoint Dragging: Reassign mappings by dragging connection endpoints
  • Real-time Preview: View transformations with sample data
  • Import/Export: Save and load mappings as JSON

Installation

npm install @expeed/ngx-data-mapper

Peer Dependencies

npm install @angular/cdk @angular/material

Usage

Basic Usage

import { Component } from '@angular/core';
import { DataMapperComponent, JsonSchema, FieldMapping } from '@expeed/ngx-data-mapper';

@Component({
  selector: 'app-mapper',
  standalone: true,
  imports: [DataMapperComponent],
  template: `
    <data-mapper
      [sourceSchema]="sourceSchema"
      [targetSchema]="targetSchema"
      [sampleData]="sampleData"
      (mappingsChange)="onMappingsChange($event)"
    />
  `
})
export class MapperComponent {
  sourceSchema: JsonSchema = {
    type: 'object',
    title: 'Source',
    properties: {
      firstName: { type: 'string', title: 'First Name' },
      lastName: { type: 'string', title: 'Last Name' },
      birthDate: { type: 'string', format: 'date', title: 'Birth Date' }
    }
  };

  targetSchema: JsonSchema = {
    type: 'object',
    title: 'Target',
    properties: {
      fullName: { type: 'string', title: 'Full Name' },
      age: { type: 'integer', title: 'Age' }
    }
  };

  sampleData = {
    firstName: 'John',
    lastName: 'Doe',
    birthDate: '1990-05-15'
  };

  onMappingsChange(mappings: FieldMapping[]): void {
    console.log('Mappings:', mappings);
  }
}

With Schema Document (Multiple Definitions)

import { SchemaDocument } from '@expeed/ngx-data-mapper';

sourceSchema: SchemaDocument = {
  $defs: {
    Customer: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        email: { type: 'string' }
      }
    }
  }
};

// Reference specific definition
sourceSchemaRef = '#/$defs/Customer';
<data-mapper
  [sourceSchema]="sourceSchema"
  [targetSchema]="targetSchema"
  [sourceSchemaRef]="sourceSchemaRef"
  [targetSchemaRef]="targetSchemaRef"
  (mappingsChange)="onMappingsChange($event)"
/>

Import/Export Mappings

import { ViewChild } from '@angular/core';
import { DataMapperComponent } from '@expeed/ngx-data-mapper';

@ViewChild(DataMapperComponent) mapper!: DataMapperComponent;

exportMappings(): void {
  const json = this.mapper.exportMappings();
  // Save to file or API
}

importMappings(json: string): void {
  this.mapper.importMappings(json);
}

clearMappings(): void {
  this.mapper.clearAllMappings();
}

API Reference

DataMapperComponent

Inputs

InputTypeDefaultDescription
sourceSchemaJsonSchema | SchemaDocument-Source schema definition
targetSchemaJsonSchema | SchemaDocument-Target schema definition
sourceSchemaRefstring-JSON pointer to source definition (e.g., #/$defs/Source)
targetSchemaRefstring-JSON pointer to target definition (e.g., #/$defs/Target)
sampleDataRecord<string, unknown>{}Sample data for transformation preview

Outputs

OutputTypeDescription
mappingsChangeEventEmitter<FieldMapping[]>Emits when mappings change

Public Methods

MethodReturnsDescription
exportMappings()stringExport all mappings as JSON
importMappings(json: string)voidImport mappings from JSON
clearAllMappings()voidRemove all mappings

Transformations

Available transformation types:

TypeDescriptionExample
uppercaseConvert to uppercase"hello" → "HELLO"
lowercaseConvert to lowercase"HELLO" → "hello"
trimRemove whitespace" hello " → "hello"
concatConcatenate multiple fields"John" + "Doe" → "John Doe"
substringExtract part of string"hello"[0:3] → "hel"
replaceReplace text"hello" → "hi"
maskMask characters"1234567890" → "******7890"
dateFormatFormat date"2024-01-15" → "Jan 15, 2024"
numberFormatFormat number1234.5 → "1,234.50"
templateTemplate string"firstName{firstName} {lastName}"
datePartExtract date partExtract year, month, day

Array Mapping

Array to Array

Map arrays with optional filtering:

// Filter array items
{
  type: 'array-mapping',
  filter: {
    conditions: [
      { field: 'status', operator: 'equals', value: 'active' }
    ]
  }
}

Array to Object

Select single item from array:

ModeDescription
firstSelect first item
lastSelect last item
conditionSelect item matching condition

Default Values

Set default values for unmapped target fields:

TypeDescription
staticFixed value
nullNull value
empty-stringEmpty string
empty-arrayEmpty array []
empty-objectEmpty object {}
current-dateCurrent date
current-datetimeCurrent date and time
uuidGenerated UUID

Styling

Customize appearance with CSS custom properties:

data-mapper {
  --data-mapper-bg: #f8fafc;
  --data-mapper-panel-bg: #ffffff;
  --data-mapper-text-primary: #1e293b;
  --data-mapper-text-secondary: #64748b;
  --data-mapper-accent-primary: #6366f1;
  --data-mapper-connector-color: #6366f1;
  --data-mapper-border-color: #e2e8f0;
}

Dark Theme

data-mapper {
  --data-mapper-bg: #1e293b;
  --data-mapper-panel-bg: #334155;
  --data-mapper-text-primary: #f1f5f9;
  --data-mapper-text-secondary: #cbd5e1;
  --data-mapper-accent-primary: #818cf8;
  --data-mapper-connector-color: #818cf8;
  --data-mapper-border-color: #475569;
}

Exports

// Components
export { DataMapperComponent } from './lib/components/data-mapper/data-mapper.component';
export { SchemaTreeComponent } from './lib/components/schema-tree/schema-tree.component';

// Services
export { MappingService } from './lib/services/mapping.service';
export { TransformationService } from './lib/services/transformation.service';
export { SchemaParserService } from './lib/services/schema-parser.service';
export { SvgConnectorService } from './lib/services/svg-connector.service';

// Types
export { JsonSchema, SchemaDocument } from './lib/models/json-schema.model';
export { FieldMapping, FieldReference } from './lib/models/field-mapping.model';
export { TransformationConfig, TransformationType } from './lib/models/transformation.model';
export { ArrayMapping, ArrayToObjectMapping } from './lib/models/array-mapping.model';
export { DefaultValue, DefaultValueType } from './lib/models/default-value.model';
export { SchemaTreeNode, FieldType } from './lib/models/schema-tree.model';

Requirements

  • Angular 19+
  • Angular Material 19+
  • Angular CDK 19+

License

Apache 2.0