Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unflatten partial arrays #130

Open
willgarcia opened this issue Aug 27, 2021 · 0 comments
Open

Unflatten partial arrays #130

willgarcia opened this issue Aug 27, 2021 · 0 comments

Comments

@willgarcia
Copy link

willgarcia commented Aug 27, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant