diff --git a/src/utils.ts b/src/utils.ts index 46b02cc..ac27731 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,6 +62,8 @@ export const renameWithAttributes = (str: string, append = '_attributes') => { for(let i = parts.length - 2; i > 0; i--) { if(parts[i].charAt(parts[i].length - 1) !== ']') { parts[i] = `${parts[i]}${append}` + } else { + parts[i].replace('[', '_attributes[') } } @@ -89,7 +91,7 @@ export const renameObjectWithAttributes = (data: T, str = '_attributes') => { const recursiveRename = (data: NestedObject, str) => { Object.entries(data).forEach(([key, value]) => { - if(isPlainObject(value)) { + if(isPlainObject(value) || Array.isArray(value)) { renameKey(data, key, `${key}${str}`) // @ts-ignore - Can't figure out how to type arbitrarily deep nested objects recursiveRename(value, str)