Skip to content

Unflatten partial arrays #130

@willgarcia

Description

@willgarcia

Flattened arrays with indexes that don't start at 0 can't easily be unflattened.

Example:

const testData = {
  'complexObject.1.node.id': 'my-test-id',
}

const data = unflatten(testData) as object

console.log(JSON.stringify(data))

The output is:

{ "complexObject": [null, { "node": { "id": "my-test-id" } }] }

Is there a way to retrieve an unflattened version of testData that does not contain a "null" item? The result I'm trying to achieve is:

{ "complexObject": [{ "node": { "id": "my-test-id" } }] }

The reason my indexes don't start at 0 is because the algorithm I'm building is filtering items in arrays, so it is expected to have non sequential indexes / indexes not starting at 0 in the initial flattened structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions