monoidmap-aeson-0.0.0.5: JSON support for monoidmap.
Copyright© 2022–2025 Jonathan Knowles
LicenseApache-2.0
Safe HaskellNone
LanguageHaskell2010

Data.MonoidMap.JSON

Description

 
Synopsis

    Introduction

    This module provides instances of ToJSON and FromJSON for MonoidMap.

    These instances provide objects of type MonoidMap k v with a JSON encoding that is identical to objects of type Map k v, which are serialised as either JSON objects or arrays depending on the key type k.

    Examples

    Encoding as JSON objects

    >>> encode $ MonoidMap.fromList [("abc", Sum 1), ("def", Sum 2)]
    
    "{\"abc\":1,\"def\":2}"
    

    Encoding as JSON arrays

    >>> encode $ MonoidMap.fromList [((1,2), Sum 3), ((2,3), Sum 5)]
    
    "[[[1,2],3],[[2,3],5]]"
    

    Laws

    Encoding to JSON

    The ToJSON instance satisfies the following laws:

    toEncoding == toEncoding . MonoidMap.toMap
    toJSON     == toJSON     . MonoidMap.toMap
    

    Decoding from JSON

    The FromJSON instance satisfies the following law:

    parseJSON == fmap (fmap MonoidMap.fromMap) parseJSON
    

    Mappings from keys to values that decode to mempty are not included in decoded MonoidMap objects.

    Orphan instances

    (FromJSONKey k, Ord k, FromJSON v, MonoidNull v) => FromJSON (MonoidMap k v) Source # 
    Instance details

    (ToJSONKey k, ToJSON v) => ToJSON (MonoidMap k v) Source # 
    Instance details