0

I have this program that very well returns me the JSON response. But i am wondering how can i access these JSON properties individually to do data analysis on these JSON objects.

val in = Source.fromURL("https://api.github.com/search/repositories?q=tetris")
val ouput = in.getLines //> ouput : List[String]

val output = in.getLines.ToList gives following output: //> ouput : List[String] =

List({"total_count":5487,"incomplete_results":false,
                                                              //| "items":[{"id":3477759,"name":"tetris","full_name":"tdd-elevator-training/te
                                                              //| tris","owner":{"login":"tdd-elevator-training","id":1227498,"avatar_url":"ht
                                                              //| tps://avatars.githubusercontent.com/u/1227498?v=3","gravatar_id":"","url":"h
                                                              //| ttps://api.github.com/users/tdd-elevator-training","html_url":"https://githu
                                                              //| b.com/tdd-elevator-training","followers_url":"https://api.github.com/users/t
                                                              //| dd-elevator-training/followers","following_url":"https://api.github.com/user
                                                              //| s/tdd-elevator-training/following{/other_user}","gists_url":"https://api.git
                                                              //| hub.com/users/tdd-elevator-training/gists{/gist_id}","starred_url":"https://
                                                              //| api.github.com/users/tdd-elevator-training/starred{/owner}{/repo}","subscrip
                                                              //| tions_url":"https://api.github.com/users/tdd-elevator-training/subscriptions
                                                              //| ","organizations_url":"https://api.github.com/users/tdd-elevator-training/or
                                                              //| gs","repos_url":"https:/
                                                              //| Output exceeds cutoff limit.

        I want to use this information, access each and every(even nested) json responses. How can i do that?
Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98
  • 1
    just google "working with JSON in scala" – dk14 May 23 '15 at 18:52
  • Didn't get any relevant info by this! Can you please share the article which answer this. – Sahil Sharma May 23 '15 at 19:07
  • maybe I have a different google. The first link - https://www.playframework.com/documentation/2.0/ScalaJson. And there is several(!) duplicating questions and answers here on stackoverflow. I'm just as lazy as you to look it up......... Ok I'm not **so** lazy - http://stackoverflow.com/questions/8054018/what-json-library-to-use-in-scala – dk14 May 23 '15 at 19:11
  • as you can see there is plenty of libraries. Scala's built-in JSON support is not recommended as it's screwed up (imho) and gonna be deprecated – dk14 May 23 '15 at 19:16
  • You need a json parser. Could use one written in java such as Jackson. For one in scala search for "json parser for scala". Argonaut at http://argonaut.io/ looks like it may be good + it is in maven. scala has json parsing support in scala.util.parsing.json (2.11.6) but Ordersky wound up using JavaTokenParsers in Programming in Scala ch33 where he gives a complete example of a json parser. –  May 26 '15 at 06:40

0 Answers0