Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

VirtusLab/scala-yaml

Repository files navigation

Scala Yaml

Scala Yaml is a dependency-free Scala library that allows you to work with YAML.

The goal of this project is to create an idiomatic library which:

  • provides compile time type safety
  • semiautomatically derives codec instances
  • has explicit error handling and helpful error messages
  • cross compiles to Scala.js and Scala Native (waiting for Scala 3 support in SN)

Please see the guide for more information

Help us create our roadmap!

Take part in our discussions, post your ideas, vote for feature requests, and have a real impact on how our next milestone will look like!

Usage

Add as a dependency:

  • via sbt
libraryDependencies += "org.virtuslab" %% "scala-yaml" % ""
  • via scala-cli
//> using dep org.virtuslab::scala-yaml:

and use it in your code!

import org.virtuslab.yaml.*

case class Address(city: String, zipcode: String) derives YamlCodec
case class Person(name: String, age: Int, address: Address) derives YamlCodec

val yaml = s"""name: John Wick
|age: 40
|address:
| city: Anywhere
| zipcode: 12-345
|""".stripMargin

val decoded = yaml.as[Person]
// Either[YamlError, Person] = Right(Person(John Wick,40,Address(Anywhere,12-345)))

case class Activity(kind: String, distance: Seq[Double]) derives YamlCodec

val activity = Activity("running", Seq(5.37, 4.98, 5.73))
val encoded = activity.asYaml
//kind: running
//distance:
// - 5.37
// - 4.98
// - 5.73

About

Resources

Readme

License

Apache-2.0 license

Stars

Watchers

Forks

Packages

Contributors