parser

io.circe.config.parser$
object parser extends Parser

Utilities for parsing com.typesafe.config.Config sources to io.circe.Json as well as decoding to a specific type.

If you are working in something like cats.effect.IO, or some other type F[_] that provides a cats.ApplicativeError, there're also decoders for loading such types.

Attributes

See also:
Example:
scala> import com.typesafe.config.ConfigFactory
scala> import io.circe.config.parser
scala> val config = ConfigFactory.parseString("server { host = localhost, port = 8080 }")
scala> val json: Either[io.circe.ParsingFailure, io.circe.Json] = parser.parse(config)
scala> json.map(_.noSpaces).getOrElse("Parse failure")
res0: String = {"server":{"port":8080,"host":"localhost"}}
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class AppSettings(server: ServerSettings)
scala> parser.decode[AppSettings](config)
res1: Either[io.circe.Error, AppSettings] = Right(AppSettings(ServerSettings(localhost,8080)))
scala> parser.decodePath[ServerSettings](config, "server")
res2: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080))
scala> import cats.effect.IO
scala> parser.decodePathF[IO, ServerSettings](config, "server")
res3: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))
Source:
parser.scala
Graph
Supertypes
trait Parser
trait Serializable
class Object
trait Matchable
class Any
Self type
parser.type

Members list

Concise view

Value members

Concrete methods

final def decode[A : Decoder](): Either[Error, A]

Load the default configuration and decode an instance at a specific path.

Load the default configuration and decode an instance at a specific path.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings)
scala> case class AppSettings(http: HttpSettings)
scala> parser.decode[AppSettings]()
res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Source:
parser.scala
final def decode[A : Decoder](config: Config): Either[Error, A]

Load the default configuration and decode an instance at a specific path.

Load the default configuration and decode an instance at a specific path.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings)
scala> case class AppSettings(http: HttpSettings)
scala> import com.typesafe.config.ConfigFactory
scala> val config = ConfigFactory.load()
scala> parser.decode[AppSettings](config)
res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Source:
parser.scala
final def decodeAccumulating[A : Decoder](config: Config): ValidatedNel[Error, A]

Attributes

Source:
parser.scala
final def decodeF[F[_], A : Decoder]()(implicit evidence$8: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

Load default configuration and decode an instance supporting cats.ApplicativeError.

Load default configuration and decode an instance supporting cats.ApplicativeError.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings)
scala> case class AppSettings(http: HttpSettings)
scala> import cats.effect.IO
scala> parser.decodeF[IO, AppSettings]()
res0: cats.effect.IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Source:
parser.scala
final def decodeF[F[_], A : Decoder](config: Config)(implicit evidence$10: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

Decode an instance supporting cats.ApplicativeError.

Decode an instance supporting cats.ApplicativeError.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings)
scala> case class AppSettings(http: HttpSettings)
scala> import com.typesafe.config.ConfigFactory
scala> val config = ConfigFactory.load()
scala> import cats.effect.IO
scala> parser.decodeF[IO, AppSettings](config)
res0: cats.effect.IO[AppSettings] = IO(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Source:
parser.scala
final def decodeFile[A : Decoder](file: File): Either[Error, A]

Load configuration from file and decode an instance.

Load configuration from file and decode an instance.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> case class HttpSettings(server: ServerSettings)
scala> case class AppSettings(http: HttpSettings)
scala> parser.decodeFile[AppSettings](new java.io.File("config/src/test/resources/application.conf"))
res0: Either[io.circe.Error, AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080))))
Source:
parser.scala
final def decodeFileAccumulating[A : Decoder](file: File): ValidatedNel[Error, A]

Attributes

Source:
parser.scala
final def decodePath[A : Decoder](path: String): Either[Error, A]

Load the default configuration and decode an instance.

Load the default configuration and decode an instance.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> parser.decodePath[ServerSettings]("http.server")
res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080))
Source:
parser.scala
final def decodePath[A : Decoder](config: Config, path: String): Either[Error, A]

Decode of an instance at a specific path.

Decode of an instance at a specific path.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> import com.typesafe.config.ConfigFactory
scala> val config = ConfigFactory.load()
scala> parser.decodePath[ServerSettings](config, "http.server")
res0: Either[io.circe.Error, ServerSettings] = Right(ServerSettings(localhost,8080))
Source:
parser.scala
final def decodePathF[F[_], A : Decoder](path: String)(implicit evidence$9: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

Load default configuration and decode an instance supporting cats.ApplicativeError at a specific path.

Load default configuration and decode an instance supporting cats.ApplicativeError at a specific path.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> import cats.effect.IO
scala> parser.decodePathF[IO, ServerSettings]("http.server")
res0: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))
Source:
parser.scala
final def decodePathF[F[_], A : Decoder](config: Config, path: String)(implicit evidence$11: Decoder[A], ev: ApplicativeError[F, Throwable]): F[A]

Decode an instance supporting cats.ApplicativeError at a specific path.

Decode an instance supporting cats.ApplicativeError at a specific path.

Attributes

Example:
scala> import io.circe.generic.auto._
scala> case class ServerSettings(host: String, port: Int)
scala> import com.typesafe.config.ConfigFactory
scala> val config = ConfigFactory.load()
scala> import cats.effect.IO
scala> import io.circe.config.parser
scala> parser.decodePathF[IO, ServerSettings](config, "http.server")
res0: cats.effect.IO[ServerSettings] = IO(ServerSettings(localhost,8080))
Source:
parser.scala

Attributes

Source:
parser.scala
final def parse(config: Config): Either[ParsingFailure, Json]

Attributes

Source:
parser.scala
final def parse(input: String): Either[ParsingFailure, Json]

Attributes

Source:
parser.scala
final def parseFile(file: File): Either[ParsingFailure, Json]

Attributes

Source:
parser.scala

Attributes

Source:
parser.scala
final def parsePath(config: Config, path: String): Either[ParsingFailure, Json]

Attributes

Source:
parser.scala

Inherited methods

final def decode[A : Decoder](input: String): Either[Error, A]

Attributes

Inherited from:
Parser
Source:
Parser.scala

Attributes

Inherited from:
Parser
Source:
Parser.scala