Type representing json value according to spec
getIn : List String -> JsonValue -> Result String JsonValue
Get json value at given path
ObjectValue [ ( "foo", StringValue "bar" ) ]
|> getIn [ "foo" ]
|> Expect.equal (Ok <| StringValue "bar")
setIn : List String -> JsonValue -> JsonValue -> Result String JsonValue
Set json value at given path
ObjectValue [ ( "foo", NullValue ) ]
|> setIn [ "foo" ] (StringValue "bar")
|> Expect.equal
(Ok (ObjectValue [ ( "foo", StringValue "bar" ) ]))
setPropertyName : ( List String, Basics.Int ) -> String -> JsonValue -> Result String JsonValue
Rename property in json value
StringValue "bar"
|> inObjWithProp "foo"
|> setPropertyName ( [], 0 ) "bam"
|> Expect.equal (Ok <| ObjectValue <| [ ( "bam", StringValue "bar" ) ])
deleteIn : List String -> JsonValue -> Result String JsonValue
Delete path in json object
decoder : Json.Decode.Decoder JsonValue
Decoder for JsonValue
[ ( "str", Json.Encode.string "value" )
, ( "array"
, Json.Encode.list
[ Json.Encode.int 10
, Json.Encode.float 0.1
, Json.Encode.bool False
, Json.Encode.null
]
)
]
|> object
|> Json.Decode.decodeValue decoder
|> Expect.equal
(Ok <|
ObjectValue
[ ( "str", StringValue "value" )
, ( "array"
, ArrayValue
[ NumericValue 10
, NumericValue 0.1
, BoolValue False
, NullValue
]
)
]
)
encode : JsonValue -> Json.Decode.Value
Encoder for JsonValue
[ ( "str", StringValue "value" )
, ( "array"
, ArrayValue
[ NumericValue 10
, NumericValue 0.1
, BoolValue False
, NullValue
]
)
]
|> ObjectValue
|> encode
|> Expect.equal
([ ( "str", Json.Encode.string "value" )
, ( "array"
, Json.Encode.list
[ Json.Encode.int 10
, Json.Encode.float 0.1
, Json.Encode.bool False
, Json.Encode.null
]
)
]
|> object
)
decodeValue : Json.Decode.Value -> JsonValue
A helper function to decode value. JsonValue decoder always succeeds, this helper aims to reduce unnecessary noise in code.