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 PropertyTape tree structure like this:
return new ArrayPropertyType(
[
new ObjectPropertyType('XyzRowEntity', [
new PropertyItem('id', [new NumberPropertyType(), new NullPropertyType()]),
new PropertyItem('name', [new StringPropertyType()]),
new PropertyItem('description', [new StringPropertyType(), new UndefinedPropertyType()]),
new PropertyItem('isActive', [new BooleanPropertyType()]),
new PropertyItem('tags', [
new ArrayPropertyType(
[new StringPropertyType()]
),
new NullPropertyType()
]),
new PropertyItem('scripts', [
new ArrayPropertyType(
[new AnyPropertyType()]
),
]),
new PropertyItem('profile', [
new ObjectPropertyType('profile', [
new PropertyItem('age', [new NumberPropertyType()]),
new PropertyItem('location', [new StringPropertyType()])
])
]),
new PropertyItem('preferences', [
new ArrayPropertyType(
[
new ObjectPropertyType('preference', [
new PropertyItem('key', [new StringPropertyType()]),
new PropertyItem('value', [new StringPropertyType()])
])
])
])
])
]);
The PropertyTape tree structure can be rendered as TypeScript interface definitions with the SchemeGenerator:
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; }
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 PropertyTape tree structure like this:
const json = JSON.stringify(demoData); const rootPropertyType: PropertyType = new PropertyTypeService().json2PropertyType(json, 'XyzRows');