harness.zio.json.extensions.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harness-zio-json_3 Show documentation
Show all versions of harness-zio-json_3 Show documentation
Miscellaneous libraries/utilities for Scala.
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