PrettyExpressive.Json
Serialize a Doc tree to a compact JSON string for debugging or interop.
docToJson :
Doc cost -> String
Convert a Doc cost to a compact JSON string.
Each Doc variant is encoded as a JSON object with a "type" field:
DocFail→{"type":"fail"}DocText→{"type":"text","string":"...","width":N}DocNewline→{"type":"newline","flatForm":"..."}or{"type":"newline","flatForm":null}DocConcat→{"type":"concat","a":{...},"b":{...}}DocChoice→{"type":"choice","a":{...},"b":{...}}DocNest→{"type":"nest","indent":N,"doc":{...}}DocAlign→{"type":"align","doc":{...}}DocReset→{"type":"reset","doc":{...}}DocAddCost→{"type":"addCost","doc":{...}}(cost value is opaque and omitted)DocTwoColumns→{"type":"twoColumns","rows":[{"a":{...},"b":{...}},...] }DocBlank→{"type":"blank","width":N}(internal renderer node)DocContext→{"type":"context"}(internal renderer node; function not inspectable)DocEvaled→{"type":"evaled"}(internal renderer node; measures not inspectable)
String values are JSON-escaped: \ and " are escaped, and the control
characters \n, \r, and \t are replaced with their JSON escape sequences.