# Flattening YFinance.jl JSON result into a DataFrame

**URL:** <https://discourse.julialang.org/t/flattening-yfinance-jl-json-result-into-a-dataframe/96333>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 20, 2023, 9:06am UTC](https://discourse.julialang.org/t/flattening-yfinance-jl-json-result-into-a-dataframe/96333 "2023-03-20T09:06:23Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [March 26, 2023, 12:10am UTC](https://discourse.julialang.org/t/flattening-yfinance-jl-json-result-into-a-dataframe/96333/21 "2023-03-26T00:10:02Z")

</div>

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:

```julia
# 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
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 😜

---

_[View the full topic](https://discourse.julialang.org/t/flattening-yfinance-jl-json-result-into-a-dataframe/96333)._
