v / examples
Raw file | 49 loc (38 sloc) | 1007 bytes | Latest commit hash 017ace6ea
1import toml
2import toml.to
3
4// Complete text from the example in the README.md:
5// https://github.com/toml-lang/toml/blob/3b11f6921da7b6f5db37af039aa021fee450c091/README.md#Example
6const toml_text = '# This is a TOML document.
7
8title = "TOML Example"
9
10[owner]
11name = "Tom Preston-Werner"
12dob = 1979-05-27T07:32:00-08:00 # First class dates
13
14[database]
15server = "192.168.1.1"
16ports = [ 8000, 8001, 8002 ]
17connection_max = 5000
18enabled = true
19
20[servers]
21
22 # Indentation (tabs and/or spaces) is allowed but not required
23 [servers.alpha]
24 ip = "10.0.0.1"
25 dc = "eqdc10"
26
27 [servers.beta]
28 ip = "10.0.0.2"
29 dc = "eqdc10"
30
31[clients]
32data = [ ["gamma", "delta"], [1, 2] ]
33
34# Line breaks are OK when inside arrays
35hosts = [
36 "alpha",
37 "omega"
38]'
39
40fn main() {
41 doc := toml.parse_text(toml_text) or { panic(err) }
42 title := doc.value('title').string()
43 println('title: "${title}"')
44 ip := doc.value('servers.alpha.ip').string()
45 println('Server IP: "${ip}"')
46
47 toml_json := to.json(doc)
48 println(toml_json)
49}