« Return to Thread: Doing a recursive JSON.readFull

Re: Doing a recursive JSON.readFull

by Naftoli Gugenheim :: Rate this Message:

Reply to Author | View in Thread

It's a Seq of pairs? So why not just transform it with recursive pattern matching to Map(seq: _*) or while you're at it, to java collections, also shouldn't be too hard--just foreach and say case (key, value)=>jmap.put(key,value) etc. 2.8 should have bidirectional conversions anyway.

-------------------------------------
Mario Camou<mcamou@...> wrote:

Hi all,
I need to read some JSON data from a server. I need the data to be parsed
into Maps of Lists of Maps (or Maps of Maps, or Lists of Lists of Maps, you
get the idea). I was going through the scaladocs for the Scala library and
found scala.util.parsing.json.JSON.parseFull, whose docs state that it
"Parse the given JSON string and return either a List[Any] if the JSON
string specifies an Array, or a Map[String,Any] if the JSON string specifies
an object". I thought that was just what I needed, but it turns out it works
only for the first level, and it leaves any lower structures as lists of
pairs instead of Maps.

Has anyone here worked with a JSON parser that does what I need? I can
always write a method to convert from one representation to the other, but I
thought I'd ask around first.

Now that I think about it, I'll probably have to go with a Java library or
build my own, since I actually need the Lists and Maps to be the Java
variants (since I'm going to have to pass them to JRuby).

Any ideas?

Thanks,
-Mario.

--
I want to change the world but they won't give me the source code.

 « Return to Thread: Doing a recursive JSON.readFull