Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created January 13, 2012 13:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kmizu/1606340 to your computer and use it in GitHub Desktop.
Usage of globalNumberParser of scala.util.parsing.json.JSON
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.util.parsing.json._
import scala.util.parsing.json._
scala> JSON.globalNumberParser = {in => try { in.toInt } catch { case e => in.toDouble}}
JSON.globalNumberParser: String => Any = <function1>
scala>
scala> JSON.parseFull("""{"n1":1, "n2":1.6}""")
res0: Option[Any] = Some(Map(n1 -> 1, n2 -> 1.6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment