score:0

Accepted answer

Have you tried using map on the parser output instead.

Edit: this compiles on my machine

import java.io.FileReader
import scala23.JSON


class JSONTest extends JSON {
  def main(args: String) {
    val reader = new FileReader(args)
    val header = ("abc", "def")
//    println(parseAll(value, reader).map(addHeader(_, header)))
    println(parseAll(value, reader).map(addHeader(_, header)))
  }
  def addHeader(xyz:Any, header:(String, Any)):Any = xyz match {
    case obj:Map[String, Any] => obj.map {
      case (k, m:Map[String, Any]) => (k, addHeader(m, header))
      case e => e
    } + header
    case arr:List[Any] => arr.map(addHeader(_, header))
    case e => e
  }
}

It should be handling the varied output of the parse better.


Related Query

More Query from same tag