scala lift json: pattern match on unknown data? -
i have strange json cannot change, , wish parse using jsonparsen in lift.
a typical json like:
{"name":"xxx", "data":{ "data_123456":{"id":"hello"}, "data_789901":{"id":"hello"}, "data_987654":{"id":"hello"}, }}
the issue keys data unknown (data_xxxxx, xx:s not known). bad json, have live it.
how supposed setup case-classes in scala able build proper structure when keys here unknown, structure known?
you can use map, , every value can jvalue too, representing unparsed json. example:
case class id(id: string) case class data(name: jvalue, data: map[string, id])
and then:
json.extract[data] res0: data(jstring(xxx),map(data_123456 -> id(hello), data_789901 -> id(hello), data_987654 -> id(hello)))
Comments
Post a Comment