# TOML.print NamedTuple

**URL:** https://discourse.julialang.org/t/toml-print-namedtuple/114780
**Category:** General Usage
**Tags:** question
**Created:** [May 27, 2024, 12:41pm UTC](https://discourse.julialang.org/t/toml-print-namedtuple/114780 "2024-05-27T12:41:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alessandra\_Bonfanti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alessandra_bonfanti/32/209529_2.png) [@Alessandra\_Bonfanti](https://discourse.julialang.org/u/Alessandra_Bonfanti)
#### Post date: [May 27, 2024, 12:41pm UTC](https://discourse.julialang.org/t/toml-print-namedtuple/114780/1 "2024-05-27T12:41:25Z")

</div>

Hi all,

I am trying to write a function that should create a .toml file. Here is a simplified version:

using TOML  
data = Dict(“settings” =\> (a = 2, b = 3))  
fname = “example.toml”  
open(fname, “w”) do io  
TOML.print(io, data)  
end

Unfortunately I get the following error that I am not sure how to deal with:  
type `@NamedTuple{a::Int64, b::Int64}` is not a valid TOML type, pass a conversion function to `TOML.print`

Thanks ever so much to everyone!

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [May 27, 2024, 1:49pm UTC](https://discourse.julialang.org/t/toml-print-namedtuple/114780/2 "2024-05-27T13:49:12Z")

</div>

`(a = 2, b = 3)` is a named tuple and from the error message it is clear that TOML doesn’t support that. The easiest solution is probably to pass a Dict instead:

```julia
data = Dict(“settings” => Dict("a" => 2, "b" => 3)))

```

or if your data was already given as named tuple, the slightly more obscure

```julia
data = Dict(“settings” => pairs((a = 2, b = 3)))

```

---

<div class="post-metadata">

### Author: ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)
#### Post date: [May 27, 2024, 1:50pm UTC](https://discourse.julialang.org/t/toml-print-namedtuple/114780/3 "2024-05-27T13:50:12Z")

</div>

As the error message says, `TOML.print` doesn’t by default have a rule on how to write the `NamedTuple` `(a=2, b=3)`.

Simplest way is to pass `Dict("a"=>2, "b"=>3)` instead.

Or you can give a rule for named tuples by passing a conversion function. See here: [TOML · The Julia Language](https://docs.julialang.org/en/v1/stdlib/TOML/#Exporting-data-to-TOML-file)
