I don’t want to veer too much into self-promotion, but since we didn’t have a working example previously, I did want to clarify what ExpandNestedData can do:
# same jdata string as rocco_sprmnt21
julia> using ExpandNesteData
julia> jsobj = JSON3.read(jdata)
julia> ExpandNestedData.expand(jsobj) |> DataFrame
7×6 DataFrame
Row │ friends_hobbies_name friends_salary name salary friends_hobbies_frequency friends_name
│ String? Int64 String Int64 Union{Missing, Int64} String
─────┼───────────────────────────────────────────────────────────────────────────────────────────────
1 │ missing 10000 bob 13000 missing sarah
2 │ missing 5000 bob 13000 missing bill
3 │ missing 10000 marge 10000 missing rhonda
4 │ surfing 5000 marge 10000 10 mike
5 │ surfing 5000 marge 10000 15 mike
6 │ missing 10000 joe 10000 missing harry
7 │ missing 5000 joe 10000 missing sally
Or we can specify what paths we want:
julia> column_set = [
ExpandNestedData.ColumnDefinition([:name]),
ExpandNestedData.ColumnDefinition([:salary]),
]
Main.ExpandNestedData.expand(jsobj,column_set) |> DataFrame
3×2 DataFrame
Row │ name salary
│ String Int64
─────┼────────────────
1 │ bob 13000
2 │ marge 10000
3 │ joe 10000
Having done no profiling, it is almost 100% certain that @rocco_sprmnt21’s solution will outperform ExpandNestedData, but for adhoc scripts or things where the JSON isn’t too big, it’s much easier that writing a custom function each time. Plus it works for all sorts of nested things: structs, XMLDict, etc. So if you are unfamiliar with the object topology, it makes it very easy to get it into a table
Edit: just realized that @rocco_sprmnt21 's generic too. I guess we’ll have to profile them now