This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
1.0.0 1.1.0
A package providing a view for editing JSON documents with unknown structure
version 1.1.1
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 1.1.1
Committed At 2018-01-08 14:48:42 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1

Modules

README

Editable JSON

About

This package allows editing JSON files with unknown structure in an Elm view. This might be necessary e.g. for managing a noSQL server with varying document structures.

Example


import EditableValue exposing (..)

import Http
import Html exposing (..)

type alias Model =
  { editableValue : Maybe EditableValue
  }

type Msg
  = ReceivedJson (Result Http.Error EditableValue)
  | SetEditableValue EditableValue

main : Program Never Model Msg
main = Html.program
  { init = init
  , view = view
  , update = update
  , subscriptions = subscriptions
  }

init : (Model, Cmd Msg)
init =
  let
    url = "http://echo.jsontest.com/key/value/otherkey/othervalue"
    request = Http.get url decoder
    requestAdvertList msg = Http.send msg request
  in
    ( { editableValue = Nothing }
    , requestAdvertList ReceivedJson
    )

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
  case msg of
    ReceivedJson (Ok editableValue) -> ({model | editableValue = Just <| editableValue}, Cmd.none)
    ReceivedJson (Err err) -> Debug.crash <| toString err
    SetEditableValue newViewer -> ({model | editableValue = Just newViewer}, Cmd.none)

view : Model -> Html Msg
view model =
  case model.editableValue of
    Just editableValue ->
      div []
        [ Html.map SetEditableValue (editableView config editableValue)
        , br [] []
        , br [] []
        , text <| toString <| encode editableValue
        ]
    Nothing -> div [] []

subscriptions : Model -> Sub Msg
subscriptions model = Sub.none