How can I convert a json string to a scala map? -


i have nested json structure not defined. can different each time run since reading remote file. need convert json map of type map[string, any]. tried json4s , jackson parsers don't seem solve issue have. know how can achieve this?

example string:

{"body":{     "method":"string",     "events":"string",     "clients":"string",     "parameter":"string",     "channel":"string",     "metadata":{         "meta1":"string",         "meta2":"string",         "meta3":"string"     } }, "timestamp":"string"} 

the level of nesting can arbitrary , not predefined.
use case:
have map[string,any] need store in file backup. convert json string , store in file. everytime new data, need json file, convert map again , perform computation. cannot store map in memory since lose if job fails.
need solution convert json string original map had before converted it.

i tried following method json4s 3.2.11 , works:

import org.json4s._ import org.json4s.jackson.jsonmethods._  //... def jsonstrtomap(jsonstr: string): map[string, any] = {   implicit val formats = org.json4s.defaultformats    parse(jsonstr).extract[map[string, any]] } 

maybe didn't define implicit val of type formats? note don't need have implicit val within every , each method long it's findable in scope.