Skip to content

Instantly share code, notes, and snippets.

@joemfb
Created February 8, 2022 21:26
Show Gist options
  • Save joemfb/23a2e627238dccf4335c39a5900560c5 to your computer and use it in GitHub Desktop.
Save joemfb/23a2e627238dccf4335c39a5900560c5 to your computer and use it in GitHub Desktop.
=< ~/(%en-json |=(a=json `cord`(rap 3 (flop (onto a ~)))))
~% %json ..part ~ !.
|%
++ onto
~/ %onto
|= [val=json out=(list @t)]
^+ out
?~ val ['null' out]
?- -.val
%a
?~ p.val ['[]' out]
=. out ['[' out]
|- ^+ out
=. out ^$(val i.p.val)
?~(t.p.val [']' out] $(p.val t.p.val, out [',' out]))
::
%b [?:(p.val 'true' 'false') out]
%n [p.val out]
%s (scap p.val out)
::
%o
=/ viz ~(tap by p.val)
?~ viz ['{}' out]
=. out ['{' out]
|- ^+ out
=. out ^$(val q.i.viz, out [':' (scap p.i.viz out)])
?~(t.viz ['}' out] $(viz t.viz, out [',' out]))
==
::
++ scap
~/ %scap
|= [val=@t out=(list @t)]
^+ out
=. out ['"' out]
=/ len (met 3 val)
=| [i=@ud pos=@ud]
|^ ^+ out
?: =(len i)
(put '"')
=/ car (cut 3 [i 1] val)
?+ car ?: (gth car 0x1f)
$(i +(i))
=/ x (crip ['\\' 'u' ((x-co 4):co car)])
$(i +(i), pos +(i), out (put x))
%10 $(i +(i), pos +(i), out (put '\\n'))
%'"' $(i +(i), pos +(i), out (put '\\"'))
%'\\' $(i +(i), pos +(i), out (put '\\\\'))
==
++ put |=(a=@t ^+(out [a (cut 3 [pos (sub i pos)] val) out]))
--
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment