Skip to content

Instantly share code, notes, and snippets.

@mrmurphy
Created December 14, 2015 22:49
Show Gist options
  • Save mrmurphy/fb99ea92d7e63728859a to your computer and use it in GitHub Desktop.
Save mrmurphy/fb99ea92d7e63728859a to your computer and use it in GitHub Desktop.
module FancyParse (..) where
import Html exposing (div, text)
import Json.Decode exposing (object2, string, (:=), value, customDecoder, Decoder, decodeString)
type alias Foo =
{ a : String
, json : String
}
sample =
"""{"a" : "apples", "b": {"c": "see?"}}"""
objectAsString : Decoder String
objectAsString =
customDecoder value (\json -> Ok (toString json))
decoder : Decoder Foo
decoder =
object2
Foo
("a" := string)
-- This extracts a field from an object
objectAsString
-- This extracts the entire object as a string
main =
div
[]
[ text <| toString (decodeString decoder sample)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment