ENH: json_normalize
flatten lists as well
#42311
Labels
Enhancement
IO JSON
read_json, to_json, json_normalize
Nested Data
Data where the values are collections (lists, sets, dicts, objects, etc.).
Problem
Right now
json_normalize
will leave lists encountered within dictionaries intact:output:
Each entry is a
list
object in this case. I am not really sure how this is of any use really. If I for example like to do anything with the first element of each row I would have to convert this first into yet anotherDataFrame
with something like:output
Solution
It would be really useful I think, if there is a flag or something that would enable to directly flatten lists as well. Something like
json_normalize(data, flatten_list=True)
. The list index is then used as a string in the record name, e.g."a.0.b", "a.1.b"
etc.API breaking implications
Don't think this would break any API.
Alternatives
There are a few packages that already have some of this ability, but require additional dependencies and intermediate products, so are slowing down conversion:
The text was updated successfully, but these errors were encountered: