Fetching json

10 views
Skip to first unread message

David Linsin

unread,
Mar 13, 2008, 6:34:10 PM3/13/08
to liftweb
Hi there,

how would I fetch a remote json representation of a resource on the
web, using liftweb? Let's say my twitters at
http://twitter.com/statuses/user_timeline/dlinsin.json.

Thanks for your help

regards, David

David Pollak

unread,
Mar 13, 2008, 7:39:33 PM3/13/08
to lif...@googlegroups.com

David Linsin wrote:
> Hi there,
>
> how would I fetch a remote json representation of a resource on the
> web, using liftweb? Let's say my twitters at
> http://twitter.com/statuses/user_timeline/dlinsin.json.
>

lift does the HTTP server side of things. Scala has built-in support
for what you're looking for:
import scala.io.Source
import scala.util.parsing.json.JSON

val s =
Source.fromURL("http://twitter.com/statuses/user_timeline/dlinsin.json")
JSON.parseFull(s.mkString(""))

You thinking about using lift to do a front-end to Twitter?

David Linsin

unread,
Mar 14, 2008, 10:00:27 AM3/14/08
to liftweb
Thanks for your help!

> You thinking about using lift to do a front-end to Twitter?

Not really, I'm just playing around with liftweb, trying to touch
every part of the framework. I simply extend the generated lift
project to have a new site where you can check yours/your friends
twitters. Being a complete newbie considering liftweb and scala it'll
help me getting started. Maybe I'll document the steps and make it a
tutorial.

David Pollak

unread,
Mar 14, 2008, 12:42:43 PM3/14/08
to lif...@googlegroups.com
On Fri, Mar 14, 2008 at 7:00 AM, David Linsin <dli...@gmail.com> wrote:

Thanks for your help!

> You thinking about using lift to do a front-end to Twitter?

Not really, I'm just playing around with liftweb, trying to touch
every part of the framework. I simply extend the generated lift
project to have a new site where you can check yours/your friends
twitters. Being a complete newbie considering liftweb and scala it'll
help me getting started. Maybe I'll document the steps and make it a
tutorial.

Documentation => beverages of choice
 


On Mar 14, 12:39 am, David Pollak <d...@athena.com> wrote:
> David Linsin wrote:
> > Hi there,
>
> > how would I fetch a remote json representation of a resource on the
> > web, using liftweb? Let's say my twitters at
> >http://twitter.com/statuses/user_timeline/dlinsin.json.
>
> lift does the HTTP server side of things.  Scala has built-in support
> for what you're looking for:
> import scala.io.Source
> import scala.util.parsing.json.JSON
>
> val s =
> Source.fromURL("http://twitter.com/statuses/user_timeline/dlinsin.json")
> JSON.parseFull(s.mkString(""))
>
> You thinking about using lift to do a front-end to Twitter?
>
> > Thanks for your help
>
> > regards, David





--
lift, the secure, simple, powerful web framework http://liftweb.net
Collaborative Task Management http://much4.us

Jorge Ortiz

unread,
Mar 14, 2008, 3:14:25 PM3/14/08
to lif...@googlegroups.com
type DavidP = Documentation => Beverage[Choice] ?

--j "oh no..."

David Pollak

unread,
Mar 14, 2008, 3:17:21 PM3/14/08
to lif...@googlegroups.com


Jorge Ortiz wrote:
type DavidP = Documentation => Beverage[Choice] ?
  
I think I'd go with Documentation => Choice[Beverage]

I like the Choice monad better than the Beverage monad. :-)

David Linsin

unread,
Mar 25, 2008, 2:42:58 AM3/25/08
to liftweb
Hi David,

>val s =
>Source.fromURL("http://twitter.com/statuses/user_timeline/dlinsin.json")
>JSON.parseFull(s.mkString(""))

the return value from JSON.parseFull is a List of Lists. The strange
thing about this is, that the order of the elements in the List
changes randomly. Sometimes it won't change for hours, then it
suddenly changed and the code picking out items from the list fails
due to index changes.

Has anyone experienced something like that with JSON.parseFull?

Regards, David

BTW: I don't think Twitter changes it's structure of the json data
randomly

David Pollak

unread,
Mar 25, 2008, 10:02:57 AM3/25/08
to lif...@googlegroups.com

On Mar 24, 2008, at 11:42 PM, David Linsin wrote:

>
> Hi David,
>
>> val s =
>> Source.fromURL("http://twitter.com/statuses/user_timeline/
>> dlinsin.json")
>> JSON.parseFull(s.mkString(""))
>
> the return value from JSON.parseFull is a List of Lists. The strange
> thing about this is, that the order of the elements in the List
> changes randomly. Sometimes it won't change for hours, then it
> suddenly changed and the code picking out items from the list fails
> due to index changes.

Interesting... although picking stuff out of a list by index is an O
(n) operation.

>
> Has anyone experienced something like that with JSON.parseFull?

No, but this is more of a Scala-users question than a lift question.

>
> Regards, David
>
> BTW: I don't think Twitter changes it's structure of the json data
> randomly

Actually, it's not unexpected (I have some pretty intimate knowledge
of Twitter's systems). If, for some reason, the cache that's serving
the items is flushed, the cache would be rebuilt and that would lead
to a re-ordering. Also, if you hit your hourly request limit, the
data will change.

The best thing to do is dump the text value retrieved from the each
request to a file and see if the data changes.

Thanks,

David

>
>
> On Mar 14, 7:39 am, David Pollak <d...@athena.com> wrote:
>> David Linsin wrote:
>>> Hi there,
>>
>>> how would I fetch a remote json representation of a resource on the
>>> web, using liftweb? Let's say my twitters at
>>> http://twitter.com/statuses/user_timeline/dlinsin.json.
>>
>> lift does the HTTP server side of things. Scala has built-in support
>> for what you're looking for:
>> import scala.io.Source
>> import scala.util.parsing.json.JSON
>>
>> val s =
>> Source.fromURL("http://twitter.com/statuses/user_timeline/
>> dlinsin.json")
>> JSON.parseFull(s.mkString(""))
>>
>> You thinking about using lift to do a front-end to Twitter?
>>
>>> Thanks for your help
>>
>>> regards, David
>
> >

--
David Pollak
http://blog.lostlake.org

Derek Chen-Becker

unread,
Mar 25, 2008, 8:58:54 PM3/25/08
to lif...@googlegroups.com
Just to chime in here, I maintain the Scala JSON parsing code. It returns a JSON array as a List with elements in the order they came into the parser (a JSON object is returned as a Map). If you're seeing otherwise I can take a look and see if I have a bug in there. In related news, Marco Behler and I are working on a JSON serialization library that we may merge into the Scala JSON core. If anyone has any requirements or wish list items, please let me know.

Derek
Reply all
Reply to author
Forward
0 new messages