Search code examples
jsonscalacirce

Scala, circe and decoding


In scala and circe, given Json objects as follows

import io.circe._ 
import io.circe.syntax._ 

val x: Json = Json.fromString("foo")
val y: Json = List(1, 2, 3).asJson

I would like to divise a way to detect if the content of x is a really a String literal (which is the case, "foo") while y is not (its a list). Any hints ?


Solution

  • def isString(json: io.circe.Json): Boolean = json.isString
    

    Or just: x.isString, y.isString.