[racket] How to parse json from a web API

From: Andrew Dudash (drewdudash at gmail.com)
Date: Sun Jun 8 14:59:06 EDT 2014

I don't see why you would need to loop. 'hash-ref' or the more general
'dict-ref' can look up values by key.

(define anime-hash (hash-ref json-hash 'anime))
(define rating-hash (hash-ref json-hash 'rating))
(foo (hash-ref anime-hash 'title)
      (hash-ref json-hash 'episodes_watched)
      (hash-ref anime-hash 'episode_count)
      ...)



On Sun, Jun 8, 2014 at 10:02 AM, Kieran Coldron <kieran at coldron.com> wrote:

>  This is my first time using racket or any lisp like language, but so far
> I really like racket but I'm a complete noob.
>
> I am wanting to make a simple application in racket for the website
> hummingbird.me <http://hummingbird.me/users/Epictest/library>, an anime
> tracking website. Here is a mockup of the gui in racket.
> [image: mockup gui] <http://a.pomf.se/gwelbo.png>
>
>
> I want to populate this list-box with the json data from the users libary
>
> this is what the json data looks like http://pastebin.com/VXNnZGbk and
> after converting it to a hash:
>
> '(#hasheq((private . #f)
>           (id . 5419481)
>           (status . "currently-watching")
>           (episodes_watched . 12)
>           (last_watched . "2014-06-07T22:49:04.788Z")
>           (rewatched_times . 0)
>           (notes . null)
>           (notes_present . null)
>           (rewatching . #f)
>           (anime .
>            #hasheq(
>                    (url . "http://hummingbird.me/anime/baccano"
> <http://hummingbird.me/anime/baccano>)
>                    (title . "Baccano!")
>                    (status . "Finished Airing")
>                    (slug . "baccano")
>                    (alternate_title . "")
>                    (episode_count . 13)
>                    (cover_image .
> "http://static.hummingbird.me/anime/poster_images/000/002/039/large/26DCC78BD23438E7D713B8E2A825F46F_800_1094.jpg?1383481747"
> <http://static.hummingbird.me/anime/poster_images/000/002/039/large/26DCC78BD23438E7D713B8E2A825F46F_800_1094.jpg?1383481747>
> )
>                    (synopsis . "")
>                    (show_type . "TV")))
>           (rating . #hasheq(
>                    (value . "4.5")
>                    (type . "advanced"))))
>   #hasheq((private . #f)
>           (id . 5419483)
>           (status . "currently-watching")
>           (episodes_watched . 12)
>           (last_watched . "2014-06-07T22:49:22.644Z")
>           (rewatched_times . 0)
>           (notes . null)
>           (notes_present . null)
>           (rewatching . #f)
>           (anime .
>            #hasheq(
>                    (url . "http://hummingbird.me/anime/steins-gate"
> <http://hummingbird.me/anime/steins-gate>)
>                    (title . "Steins;Gate")
>                    (status . "Finished Airing")
>                    (slug . "steins-gate")
>                    (alternate_title . "")
>                    (episode_count . 24)
>                    (cover_image .
> "http://static.hummingbird.me/anime/poster_images/000/005/646/large/5646.jpg?1387138585"
> <http://static.hummingbird.me/anime/poster_images/000/005/646/large/5646.jpg?1387138585>
> )
>                    (synopsis . "")
>                    (show_type . "TV")))
>           (rating . #hasheq(
>                    (value . "5.0")
>                    (type . "advanced")))))
>
> I understand that somehow I have to loop through the the hash to get the
> data I require and possibly store it in a second hash? How would I go about
> doing this?
> Sorry if this is a stupid question and having no idea what I'm doing.
>
> --
> Kieran Coldron
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140608/3792218c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gwelbo.png
Type: image/png
Size: 16114 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20140608/3792218c/attachment-0001.png>

Posted on the users mailing list.