Skip to content

Instantly share code, notes, and snippets.

@yogaxpto
Created December 9, 2022 18:51
Show Gist options
  • Save yogaxpto/c031147b84e9e6eb589cce85555c7b4c to your computer and use it in GitHub Desktop.
Save yogaxpto/c031147b84e9e6eb589cce85555c7b4c to your computer and use it in GitHub Desktop.

Task 1:

Given an input as json array (each element is a flat dictionary) write a program that will parse this json, and return a nested dictionary of dictionaries of arrays, with keys specified in command line arguments and the leaf values as arrays of flat dictionaries matching appropriate groups

python nest.py nesting_level_1 nesting_level_2 … nesting_level_n

Example input for json can be found here: http://jsonformatter.org/74f158

When invoked like this: cat input.json | python nest.py currency country city

the output should be something like this:
http://jsonformatter.org/615048

Please note that the nesting keys should be stripped out from the dictionaries in the leaves. Also please note that the program should support an arbitrary number of arguments, that is arbitrary level of nesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment