Converts a json or object structure like this: [ { id: 1, name: 'Alice', description: 'Lorem ipsum dolor', isActive: true, tags: ['typescript', 'javascript'], scripts: [], profile: { age: 30, location: 'Berlin' }, preferences: [{ key: 'theme', value: 'dark' }] }, { id: 2, name: 'Marc', description: 'Lorem ipsum dolor', isActive: false, tags: ['java', 'javascript'], scripts: [], profile: { age: 55, location: 'Frankfurt' }, preferences: [{ key: 'theme', value: 'light' }] }, { id: null, name: 'Bob', isActive: false, tags: null, scripts: [], profile: { age: 25, location: 'Frankfurt' }, preferences: [{ key: 'language', value: 'de' }] } ]
into a TypeScript interface definitions:
export interface XyzRowEntity { description?: string; id: number|null; isActive: boolean; name: string; preferences: PreferenceEntity[]; profile: ProfileEntity; scripts: any[]; tags: string[]|null; }
export interface PreferenceEntity { key: string; value: string; }
export interface ProfileEntity { age: number; location: string; }
const json = JSON.stringify(demoData); const rootPropertyType: PropertyType = new PropertyTypeService().object2PropertyType(demoData, 'XyzRows'); console.log(new SchemeGenerator().renderTypeScriptInterfaces(rootPropertyType).join('\n'));
Converts a json or object structure like this: [ { id: 1, name: 'Alice', description: 'Lorem ipsum dolor', isActive: true, tags: ['typescript', 'javascript'], scripts: [], profile: { age: 30, location: 'Berlin' }, preferences: [{ key: 'theme', value: 'dark' }] }, { id: 2, name: 'Marc', description: 'Lorem ipsum dolor', isActive: false, tags: ['java', 'javascript'], scripts: [], profile: { age: 55, location: 'Frankfurt' }, preferences: [{ key: 'theme', value: 'light' }] }, { id: null, name: 'Bob', isActive: false, tags: null, scripts: [], profile: { age: 25, location: 'Frankfurt' }, preferences: [{ key: 'language', value: 'de' }] } ]
into a TypeScript interface definitions:
export interface XyzRowEntity { description?: string; id: number|null; isActive: boolean; name: string; preferences: PreferenceEntity[]; profile: ProfileEntity; scripts: any[]; tags: string[]|null; }
export interface PreferenceEntity { key: string; value: string; }
export interface ProfileEntity { age: number; location: string; }
const json = JSON.stringify(demoData); const rootPropertyType: PropertyType = new PropertyTypeService().object2PropertyType(demoData, 'XyzRows'); console.log(new SchemeGenerator().renderTypeScriptInterfaces(rootPropertyType).join('\n'));