I want to compare two Jsons. For that I created a recursive function that uses Pattern matching.
Something like this:
(json1, json2) match {
case (obj1: JsonObject, obj2: JsonObject) =>
...
case (arr1: JsonArray, arr2: JsonArray) =>
...
case _ =>
...
}
json1 and json2 are from the type io.circe.Json.
I tried different things:
I did not find the representation of JsonArray
JsonObject is not really related to JSON
The related classes are package private, like
private[circe] final case class JArray(value: Vector[Json])
My working solution uses the provided if-checks, like case _ if expJson.isArray && resJson.isArray =>.
Is there a better way?
We're not supposed to match.
You can use methods
Json#fold,Json#arrayOrObject,Json#foldWithorJson#isArray/asArray/isObject/asObjectClasses
JNull,JBoolean,JNumber,JString,JArray,JObjectare package-private (the package isio.circe). If you really want to access them and match you can write some your code inside the packageio.circe.