| Copyright | © 2022–2025 Jonathan Knowles | 
|---|---|
| License | Apache-2.0 | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
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",Sum1), ("def",Sum2)] "{\"abc\":1,\"def\":2}"
Encoding as JSON arrays
>>>encode$MonoidMap.fromList[((1,2),Sum3), ((2,3),Sum5)] "[[[1,2],3],[[2,3],5]]"
Laws
Encoding to JSON
The ToJSON instance satisfies the following laws:
toEncoding==toEncoding.MonoidMap.toMaptoJSON==toJSON.MonoidMap.toMap
Decoding from JSON
The FromJSON instance satisfies the following law:
parseJSON==fmap(fmapMonoidMap.fromMap)parseJSON
Mappings from keys to values that decode to mempty are not included in
 decoded MonoidMap objects.