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

flatten_preserve_lists is failed to flatten data which has array in array #72

Open
kanelee7512 opened this issue Feb 23, 2021 · 0 comments · May be fixed by #73
Open

flatten_preserve_lists is failed to flatten data which has array in array #72

kanelee7512 opened this issue Feb 23, 2021 · 0 comments · May be fixed by #73

Comments

@kanelee7512
Copy link

Test data is like:
data = { "header": "header a",
"item": [{"itemLineNumber": 1}, {"itemLineNumber": 2}],
"containerInfo":
[{ "containerId":"A",
"containerItems":[{"itemSKU":1}]},
{"containerId":"B",
"containerItems":[{"itemSKU":2}]},
{"containerId":"C",
"containerItems":[{"itemSKU":3}]},
{"containerId":"D",
"containerItems":[{"itemSKU":4}]},
{"containerId":"E",
"containerItems":[{"itemSKU":5}]}]}

Int[5]: flatten_json.flatten_preserve_lists(data, max_list_index=10, max_depth=10)
Out[8]:
[{'header': 'header a',
'containerInfo_containerItems': 1,
'containerInfo_containerId': 'E',
'item': 1},
{'header': 'header a',
'containerInfo_containerItems': 1,
'containerInfo_containerId': 'E',
'item': 2},
{'header': 'header a',
'containerInfo_containerItems': 2,
'containerInfo_containerId': 'E',
'item': 1},
{'header': 'header a',
'containerInfo_containerItems': 2,
'containerInfo_containerId': 'E',
'item': 2},
{'header': 'header a',
'containerInfo_containerItems': 3,
'containerInfo_containerId': 'E',
'item': 1},
{'header': 'header a',
'containerInfo_containerItems': 3,
'containerInfo_containerId': 'E',
'item': 2},
{'header': 'header a',
'containerInfo_containerItems': 4,
'containerInfo_containerId': 'E',
'item': 1},
{'header': 'header a',
'containerInfo_containerItems': 4,
'containerInfo_containerId': 'E',
'item': 2},
{'header': 'header a',
'containerInfo_containerItems': 5,
'containerInfo_containerId': 'E',
'item': 1},
{'header': 'header a',
'containerInfo_containerItems': 5,
'containerInfo_containerId': 'E',
'item': 2}]

The header field (parent level) and containerItems(grandchild level) and Item(child level) fields are fine. But the containerId(child level) is always overwritten by the latest array item "containerId":"E".

kanelee7512 pushed a commit to kanelee7512/flatten that referenced this issue Feb 23, 2021
@kanelee7512 kanelee7512 linked a pull request Feb 23, 2021 that will close this issue
kanelee7512 pushed a commit to kanelee7512/flatten that referenced this issue Feb 24, 2021
kanelee7512 pushed a commit to kanelee7512/flatten that referenced this issue Feb 24, 2021
kanelee7512 pushed a commit to kanelee7512/flatten that referenced this issue Feb 24, 2021
kanelee7512 pushed a commit to kanelee7512/flatten that referenced this issue Feb 24, 2021
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

Successfully merging a pull request may close this issue.

1 participant