Creating new json from old json

23 views
Skip to first unread message

Corey Nolet

unread,
Nov 26, 2014, 7:56:49 PM11/26/14
to raptur...@googlegroups.com
I've got a use case where I'm projecting new json objects out of old json objects. Let's say I've got json that looks like this (this is a very oversimplified case):

val people = "{ people: [{ id: 1, name: \"Corey\"}, {id: 2, name: \"Jon\"}], ...}"

What I'd like to do is directly pull objects  of type Json out of one object and add them to another.

val json = Json.parse(people)
val newJson = JsonBuffer.parse("{}")

newJson += people.people


This could be because I'm using an old version of Rapture-json (0.9.0) but this is throwing an exception saying JSON cannot be serialized to Json. 

Obviously my usecase is much more complex than that. We're doing many many many more complex transformations from the input json to the output json but you get the gist of what Im trying to acheive.

Corey Nolet

unread,
Nov 26, 2014, 8:08:31 PM11/26/14
to raptur...@googlegroups.com
Woops- typo. 

the line:

newJson += people.people 

should read:

newJson += json.people

Jon Pretty

unread,
Nov 26, 2014, 8:12:52 PM11/26/14
to raptur...@googlegroups.com
Hi Corey,

Yes, that's actually an issue that was fixed in about version 1.0.2. The problem is that it doesn't have implicit serializer or extractor objects for converting between `Json` and `JsonBuffer`.

What you can do is define this ugly implicit, and it should start working:

   implicit def jsonSerializer: Jsonizer[Json] = new Jsonizer[Json] {
     def jsonize(j: Json) = j.root(0)
   }

That's a simpler version of what's defined in later versions of Rapture JSON.

Jon

--
You received this message because you are subscribed to the Google Groups "Rapture users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rapture-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jon Pretty | @propensive

Corey Nolet

unread,
Nov 26, 2014, 9:08:20 PM11/26/14
to raptur...@googlegroups.com
I promise I'll update as soon as I can :-P
Reply all
Reply to author
Forward
0 new messages