waratuman/json-extra/1.0.2

Formerly waratuman/elm-json-extra. Search finds this package by either name.

Json.Decode.Extra

Helper functions for the Json.Decode module of elm/json.

nothing : Decoder ()

Decode a JSON value and do nothing with it.

import Json.Decode exposing (..)


decodeString nothing "{}" --> Ok ()
date : Decoder ( Int, Month, Int )

Decode an ISO8601 JSON string into a Posix.

import Json.Decode exposing (..)
import Time


decodeString (field "created_at" date) "{ \"created_at\": \"2019-11-22\"}"
    --> Ok (2019, Time.Nov, 22)
iso8601 : Decoder Posix

Decode an ISO8601 JSON string into a Posix.

import Json.Decode exposing (..)
import Time




decodeString (field "created_at" iso8601)
    "{ \"created_at\": \"2019-11-22T18:26:45Z\"}"
    --> Ok (Time.millisToPosix 1574447205000)
posix : Decoder Posix

Decode a JSON float value representing the number of seconds since epoch into a Posix.

import Json.Decode exposing (..)
import Time


decodeString (field "created_at" posix)
    "{ \"created_at\": 1574447205.394}"
    --> Ok (Time.millisToPosix 1574447205000)
timezone : Decoder ( String, Zone )

Decode a timezone JSON string value into a Zone.

import Json.Decode exposing (..)
import TimeZone


decodeString (field "timezone" timezone)
    "{ \"timezone\": \"America/Los_Angeles\"}"
    --> Ok ("America/Los_Angeles", TimeZone.america__los_angeles ())