Install TOON for Scala

TOON is available in multiple languages. Choose your preferred ecosystem and start integrating TOON into your projects today.

Community

Installation

Add the official toon4s package to your project

libraryDependencies += "com.github.vim89" %% "toon4s" % "0.1"

Usage Example

Quick start guide for encoding and decoding TOON format in Scala

import io.toonformat.toon4s._

val payload = Map(
  "users" -> Vector(
    Map("id" -> 1, "name" -> "Ada", "tags" -> Vector("reading", "gaming")),
    Map("id" -> 2, "name" -> "Bob", "tags" -> Vector("writing"))
  )
)

val toon = Toon.encode(payload, EncodeOptions(indent = 2)).fold(throw _, identity)
println(toon)
// users[2]{id,name,tags}:
//   1,Ada,[2]: reading,gaming
//   2,Bob,[1]: writing

val json = Toon.decode(toon).fold(throw _, identity)
println(json)

No code needed to try it: paste data into the JSON to TOON converter, compare token counts in the TOON token calculator, or read the TOON format guide.