1

I'm using the json4s library in scala. I need to import data from json, do some manipulations on it and then save it back to a json format. Here is what I have so far:

import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.JsonDSL._

def changeAFewThings(myMap: Map[String, Any]): Map[String, Any] = {
  // add and remove some items and return the updated Map
}

val rawJson = loadJsonData()
val myMap = parse(rawJson).asInstanceOf[JObject].values

val updatedMap = changeAFewThings(myMap)

val jsonString = compact(render(updatedMap))
saveJsonData(jsonString)

This throws a compilation error - No implicit view available from Any => org.json4s.JsonAST.JValue on the render() call.

What do I need to do to manipulate a Map[String, Any] into something the library can serialize? Or is this not supported and I just need to create case-class objects and do parse(rawJson).extract[MyObj] and write(myObj) instead of manipulating Maps?

davidpricedev
  • 2,107
  • 2
  • 20
  • 34

0 Answers0