flatten
flatten copied to clipboard
fixed #69 & #72
Summary
This PR should fix issue #69 and #72. It can correctly flatten the data which has a more than 10 items array. (#69) It can correctly flatten the data which has an array including another array. (#72)
Bug Fixes/New Features
Fixes #69 Fixes #72
How to Verify
Side Effects
Resolves
Fixes #69 Fixes #72
Tests
Case 1. data = ''' { "header": "header a", "orderItems":[ {"itemLineNumber":1, "itemQuantity":468 }, {"itemLineNumber":2, "itemQuantity":414 }, { "itemLineNumber":3, "itemQuantity":24 }, { "itemLineNumber":4, "itemQuantity":24 }, { "itemLineNumber":5, "itemQuantity":36 }, { "itemLineNumber":6, "itemQuantity":24 }, { "itemLineNumber":7, "itemQuantity":84 }, { "itemLineNumber":8, "itemQuantity":60}, {"itemLineNumber":9,"itemQuantity":42 }, { "itemLineNumber":10, "itemQuantity":84 }, {"itemLineNumber":11, "itemQuantity":12 }, { "itemLineNumber":12, "itemQuantity":12 }] } ''' result: [{'orderItems.itemQuantity': 468, 'orderItems.itemLineNumber': 1, 'header': 'header a'}, {'orderItems.itemQuantity': 414, 'orderItems.itemLineNumber': 2, 'header': 'header a'}, {'orderItems.itemQuantity': 12, 'orderItems.itemLineNumber': 11, 'header': 'header a'}, {'orderItems.itemQuantity': 12, 'orderItems.itemLineNumber': 12, 'header': 'header a'}, {'orderItems.itemQuantity': 24, 'orderItems.itemLineNumber': 3, 'header': 'header a'}, {'orderItems.itemQuantity': 24, 'orderItems.itemLineNumber': 4, 'header': 'header a'}, {'orderItems.itemQuantity': 36, 'orderItems.itemLineNumber': 5, 'header': 'header a'}, {'orderItems.itemQuantity': 24, 'orderItems.itemLineNumber': 6, 'header': 'header a'}, {'orderItems.itemQuantity': 84, 'orderItems.itemLineNumber': 7, 'header': 'header a'}, {'orderItems.itemQuantity': 60, 'orderItems.itemLineNumber': 8, 'header': 'header a'}, {'orderItems.itemQuantity': 42, 'orderItems.itemLineNumber': 9, 'header': 'header a'}, {'orderItems.itemQuantity': 84, 'orderItems.itemLineNumber': 10, 'header': 'header a'}]
Case 2. 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}]}]} ''' result: [{'item': 1, 'containerInfo.containerId': 'A', 'header': 'header a', 'containerInfo.containerItems': 1}, {'item': 2, 'containerInfo.containerId': 'A', 'header': 'header a', 'containerInfo.containerItems': 1}, {'item': 1, 'containerInfo.containerId': 'B', 'header': 'header a', 'containerInfo.containerItems': 2}, {'item': 2, 'containerInfo.containerId': 'B', 'header': 'header a', 'containerInfo.containerItems': 2}, {'item': 1, 'containerInfo.containerId': 'C', 'header': 'header a', 'containerInfo.containerItems': 3}, {'item': 2, 'containerInfo.containerId': 'C', 'header': 'header a', 'containerInfo.containerItems': 3}, {'item': 1, 'containerInfo.containerId': 'D', 'header': 'header a', 'containerInfo.containerItems': 4}, {'item': 2, 'containerInfo.containerId': 'D', 'header': 'header a', 'containerInfo.containerItems': 4}, {'item': 1, 'containerInfo.containerId': 'E', 'header': 'header a', 'containerInfo.containerItems': 5}, {'item': 2, 'containerInfo.containerId': 'E', 'header': 'header a', 'containerInfo.containerItems': 5}]
Code Reviewer(s)
@amirziai , @amir-ziai-zefr
Hello @kanelee7512! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
flatten_json/__init__.py:
Line 325:80: E501 line too long (81 > 79 characters)
Comment last updated at 2021-02-24 14:11:42 UTC
thanks for the PR @kanelee7512. do you mind adding your examples to the tests? i will reviewer later this week.