param value returns const isDictionary = ( value ) : value is Record < string , unknown > => value !== null && value !== undefined && typeof value === 'object' && ! Array . isArray ( value ) ; param keyMap param transformMap returns export const generateMapTransform = ( keyMap , transformMap ) => { const mapTransform = ( json ) : Record < string , unknown > => { const result = { } ; for ( const key in json ) { const newKey = keyMap [ key ] ?? key ; let value = json [ key ] ; if ( Array . isArray ( value ) ) { value = value . map ( ( nestedValue ) => { if ( isDictionary ( nestedValue ) ) { return mapTransform ( nestedValue ) ; } return nestedValue ; } ) ; } else if ( isDictionary ( value ) ) { value = mapTransform ( value as Record < string , unknown > ) ; } if ( newKey in transformMap ) { value = transformMap [ newKey ] ( value ) ; } result [ newKey ] = value ; } return result ; } ; return mapTransform ; } ;