« 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

Yeah, so it sounds like recursive pattern matching is what you want.
case (str, (l: List[_]) :: rest) => ...
should get a list of lists without issues of type erasure.

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

¡That was fast! Thanks for the quick answer and the pointers.
It's a List of Pairs, the first element of the Pair is a String, the second
can be a List of Pairs (ad infinitum), a List of Lists of Pairs, or an
atomic
object. The idea would be to convert any "List of Pairs" structure to
a corresponding Map.

I'll probably end up doing it just as an exercise (I'm a Scala
beginner). Thanks again!
-Mario.

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


On Sun, Jul 5, 2009 at 23:28, Naftoli Gugenhem <naftoligug@...> wrote:

> 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