|
4 | 4 | -- Copyright: © 2022–2025 Jonathan Knowles |
5 | 5 | -- License: Apache-2.0 |
6 | 6 | -- |
7 | | -module Data.MonoidMap.JSON where |
| 7 | +-- This module provides instances of 'ToJSON' and 'FromJSON' for 'MonoidMap'. |
| 8 | +-- |
| 9 | +-- These instances provide objects of type 'MonoidMap' __@k@__ __@v@__ with a |
| 10 | +-- JSON encoding identical to that of 'Map' __@k@__ __@v@__, serialised as |
| 11 | +-- either JSON /objects/ or /arrays/ depending on the key type __@k@__. |
| 12 | +-- |
| 13 | +-- = Examples |
| 14 | +-- |
| 15 | +-- === Encoding as JSON objects |
| 16 | +-- |
| 17 | +-- @ |
| 18 | +-- >>> 'encode' '$' 'fromList' [("abc", 'Sum' 1), ("def", 'Sum' 2)] |
| 19 | +-- "{\\"abc\\":1,\\"def\\":2}" |
| 20 | +-- @ |
| 21 | +-- |
| 22 | +-- === Encoding as JSON arrays |
| 23 | +-- |
| 24 | +-- @ |
| 25 | +-- >>> 'encode' '$' 'fromList' [((1,2), 'Sum' 3), ((2,3), 'Sum' 5)] |
| 26 | +-- "[[[1,2],3],[[2,3],5]]" |
| 27 | +-- @ |
| 28 | +-- |
| 29 | +-- = Laws |
| 30 | +-- |
| 31 | +-- == Decoding from JSON |
| 32 | +-- |
| 33 | +-- The 'FromJSON' instance satisfies the following law: |
| 34 | +-- |
| 35 | +-- @ |
| 36 | +-- 'parseJSON' '==' 'fmap' ('fmap' 'MonoidMap'.'fromMap') 'parseJSON' |
| 37 | +-- @ |
| 38 | +-- |
| 39 | +-- Mappings from keys to values that decode to 'mempty' are __not__ included in |
| 40 | +-- decoded 'MonoidMap' objects. |
| 41 | +-- |
| 42 | +-- == Encoding to JSON |
| 43 | +-- |
| 44 | +-- The 'ToJSON' instance satisfies the following laws: |
| 45 | +-- |
| 46 | +-- @ |
| 47 | +-- 'toEncoding' '==' 'toEncoding' '.' 'MonoidMap'.'toMap' |
| 48 | +-- 'toJSON' '==' 'toJSON' '.' 'MonoidMap'.'toMap' |
| 49 | +-- @ |
| 50 | +-- |
| 51 | +module Data.MonoidMap.JSON |
| 52 | + () |
| 53 | + where |
8 | 54 |
|
9 | 55 | import Prelude |
10 | 56 |
|
|
0 commit comments