aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 15836366fe33085ef2f01ff7f8b427c5e349dc86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# yamlesque

Pure Scala YAML parsing.

As the name suggests, "yam-el-esque" is a Scala implementation of the most
frequently used YAML features. It takes inspiration from [Haoyi Li's
ujson](http://www.lihaoyi.com/post/uJsonfastflexibleandintuitiveJSONforScala.html)
and aims to provide an idiomatic API that is cross-platform and has no
dependencies.

## Getting Started

Include yamlesque into a project.

- mill:

  ```scala
  def ivyDeps = Agg(ivy"io.crashbox::yamlesque::<latest_tag>")
  ```

- sbt:

  ```scala
  libraryDependencies += "io.crashbox" %%% "yamlesque" % "<latest_tag>"
  ```

**Yamlesque is available for Scala 2.13, 2.12 and 2.11, including ScalaJS and
Native.**

It should also work with Scala 2.10 and 2.9, although no pre-compiled libraries
are published for these versions.

### Read Some YAML

```scala
val text = s"""|name: yamlesque
               |description: a YAML library for scala
               |authors:
               |  - name: Jakob Odersky
               |    id: jodersky
               |  - name: Another
               |""".stripMargin

val yaml: yamlesque.Node = yamlesque.read(text)

val id = yaml.obj("authors").arr(0).obj("id").str

println(id) // == "jodersky"
```

### Write Some YAML

```scala
import yamlesque.{Arr, Num, Obj, Str}
val config = Obj(
  "auth" -> Obj(
    "username" -> Str("admin"),
    "password" -> Str("guest")
  ),
  "interfaces" -> Arr(
    Obj(
      "address" -> Str("0.0.0.0"),
      "port" -> Num(80)
    ),
    Obj(
      "address" -> Str("0.0.0.0"),
      "port" -> Num(443)
    )
  )
)

val stringly = yamlesque.write(config)

println(stringly)
```

will result in

```yaml
auth:
  username: admin
  password: guest
interfaces:
  - address: 0.0.0.0
    port: 80.0
  - address: 0.0.0.0
    port: 443.0
```

## Official YAML Conformance

Yamlesque does not strictly implement all features as defined in [YAML
1.2](http://yaml.org/spec/1.2/spec.html), however support should be
sufficient for most regular documents.

Available features:

- plain strings (i.e. scalars), including specialization to numbers, booleans
  and null
- lists and maps
- quoted strings
- comments
- multiple documents (i.e. ---)

Features which are currently not supported but for which support is planned:

- verbatim blocks (i.e. | and >) (support is limited currently)
- flow-styles (aka inline JSON)

Unsupported features with no planned implementation:

- anchors and references
- tags

Pull requests with additional feature implementations are always welcome!