# Recursive \`fieldnames()\`?

**URL:** <https://discourse.julialang.org/t/recursive-fieldnames/10852>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 12, 2018, 7:20am UTC](https://discourse.julialang.org/t/recursive-fieldnames/10852 "2018-05-12T07:20:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [May 12, 2018, 7:20am UTC](https://discourse.julialang.org/t/recursive-fieldnames/10852/1 "2018-05-12T07:20:01Z")

</div>

Is there a way to apply `fieldnames()` resursively so that all fieldnames can be printed in cascade? I know that `dump()` sort of does this, but it prints literally everything - it’s hard to pick ham from peas.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [May 12, 2018, 8:14am UTC](https://discourse.julialang.org/t/recursive-fieldnames/10852/2 "2018-05-12T08:14:41Z")

</div>

Maybe there already exists a method for this.

If not, you could write your own. Here’s an example:

```julia
function rfieldnames(::Type{T}, i::Int=0; recursive::Bool=true) where T
    fields = fieldnames(T)
    if !isempty(fields)
        for field in fields
            println(" "^i, field, "::", fieldtype(T, field))
            if recursive
                rfieldnames(fieldtype(T, field), i+1, recursive=true)
            end
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [May 12, 2018, 8:23am UTC](https://discourse.julialang.org/t/recursive-fieldnames/10852/3 "2018-05-12T08:23:01Z")

</div>

Thanks. I wish I’m so versed like you to write down the snippet in milliseconds.

It’ll be thrilling if a recursion function can be added to `fieldnames`.
