Footnotes
-- JSON.stringify 는 열거 가능한 자기 속성만 — Set·Map 은 {} 가 된다
replacer :: Key -> Value -> Value
replacer _ (SetV s) = ArrayV (toList s) -- value instanceof Set ? [...value] : value
replacer _ v = v
-- JSON.stringify(dude, replacer)
-- JSON.stringify(dude, null, "🍆") -- space 문자열로 들여쓰기 — 10자에서 잘린다
JSON Schema enables the confident and reliable use of the JSON data format.
Footnotes
-- JSON 배열 태그를 펼쳐 빈도순으로
frequencies :: [[Tag]] -> [(Tag, Int)]
frequencies = sortOn (\(t, n) -> (Down n, t)) -- ORDER BY frequency DESC, tag ASC
. map (\g -> (head g, length g)) . group . sort
. concat -- FROM example, json_each(example.tags)
-- 다시 JSON 배열로 모을 때: 바깥 ORDER BY 는 집계 안 순서를 보장하지 않는다
-- json_group_array(tag ORDER BY frequency DESC, tag ASC) -- 집계 안 ORDER BY, SQLite 3.44+
-- JSON 값 = 기본값 | 객체 | 배열, 객체·배열이 다시 JSON 값을 담는다
data JsonPrimitive = JString String | JNumber Double | JBool Bool | JNull
data JsonValue = Prim JsonPrimitive
| Obj (Map String JsonValue) -- type-fest: 선택 속성은 undefined 도 허용
| Arr [JsonValue] -- readonly 배열도
-- 직렬화 결과 타입까지 필요하면 type-fest 의 Jsonify