Module

Data.Codec.Argonaut.Migration

Package
purescript-codec-argonaut
Repository
garyb/purescript-codec-argonaut

#addDefaultField Source

addDefaultField :: String -> Json -> JsonCodec Json

When dealing with a JSON object that may be missing a field, this codec can be used to alter the JSON before parsing to ensure a default value is present instead.

#updateField Source

updateField :: String -> (Json -> Json) -> JsonCodec Json

Re-maps the value of a field in a JSON object.

#addDefaultOrUpdateField Source

addDefaultOrUpdateField :: String -> (Maybe Json -> Json) -> JsonCodec Json

When dealing with a JSON object that may be missing a field, this codec can be used to alter the JSON before parsing to ensure a default value is present instead. Similar to addDefaultField, but allows existing values to be modified also.

#renameField Source

renameField :: String -> String -> JsonCodec Json

When dealing with a JSON object that has had a field name changed, this codec can be used to alter the JSON before parsing to ensure the new field name is used instead

#nestForTagged Source

nestForTagged :: JsonCodec Json

Prepares an object from a legacy codec for use in a Variant or taggedSum codec.

For an input like: { "tag": "tag", "x": 1, "y": 2, "z": 3 } the result will be: { "tag": "tag", "value": { "x": 1, "y": 2, "z": 3 } }

For an input like: { "tag": "tag", "value": 1, "foo": 2 } the result will be: { "tag": "tag", "value": { "value": 1, "foo": 2 }

If the value is already in the expected form, where there is only value and no other keys (aside from tag): { "tag": "tag", "value": true } the result will be the same as the input.

If the tag field is missing from the input, it will also be missing in the output.