All Downloads are FREE. Search and download functionalities are using the official Maven repository.

harness.zio.json.extensions.scala Maven / Gradle / Ivy

The newest version!
package harness.zio.json

import zio.json.*
import zio.json.ast.Json

extension [A](self: A) {
  def safeToJsonAST(implicit encoder: JsonEncoder[A]): Json = {
    val encoded = self.toJson
    Json.decoder.decodeJson(encoded).getOrElse(Json.Str(encoded))
  }
}

extension (self: Json) {
  def jsonToString: String = self match
    case Json.Str(value) => value
    case _               => self.toJson
  def jsonToStringPretty: String = self match
    case Json.Str(value) => value
    case _               => self.toJsonPretty
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy