Created
December 14, 2015 22:49
-
-
Save mrmurphy/fb99ea92d7e63728859a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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