Skip to content

Instantly share code, notes, and snippets.

@deckool
Created August 14, 2014 08:45
Show Gist options
  • Save deckool/102825d0e9e24efaeecb to your computer and use it in GitHub Desktop.
Save deckool/102825d0e9e24efaeecb to your computer and use it in GitHub Desktop.
explore dead-simple-json with multiple json formats
import qualified Text.DeadSimpleJSON as JSON
import Text.DeadSimpleJSON (JSON)
main = do
let jsonData1 = read "[1,2,4,8,16]" :: JSON
print $ show jsonData1
plane = do
let jsonData = read "{\"seven\": 7, \"nine\": [1,2,4,8,16]}"
print $ (jsonData JSON.? "nine[3]" :: Int)
longer = do
let dataraw = read "{\"movielist\": [\"Friday the 13th\",\"Friday the 13th Part 2\",\"Friday the 13th Part III\",\"Friday the 13th: The Final Chapter\",\"Friday the 13th: A New Beginning\"]}"
print $ (dataraw JSON.? "movielist[3]" :: String)
nested = do
let nest = read "{\"sample\": {\"someitem\": {\"thesearecool\": [{\"neat\": \"wow\"},{\"neat\": \"tubular\"}]}}}"
print $ (nest JSON.? "sample.someitem.thesearecool[0].neat" :: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment