Get json value at given path
ObjectValue [ ( "foo", StringValue "bar" ) ]
|> getIn [ "foo" ]
|> Expect.equal (Ok <| StringValue "bar")Set json value at given path
ObjectValue [ ( "foo", NullValue ) ]
|> setIn [ "foo" ] (StringValue "bar")
|> Expect.equal
(Ok (ObjectValue [ ( "foo", StringValue "bar" ) ]))Rename property in json value
StringValue "bar"
|> inObjWithProp "foo"
|> setPropertyName ( [], 0 ) "bam"
|> Expect.equal (Ok <| ObjectValue <| [ ( "bam", StringValue "bar" ) ])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
]
)
]
)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
)A helper function to decode value. JsonValue decoder always succeeds, this helper aims to reduce unnecessary noise in code.
Type representing json value according to spec