[racket] Json pretty-print

From: Sean McBeth (sean.mcbeth at gmail.com)
Date: Tue Apr 16 14:05:01 EDT 2013

I've had good luck porting simple Python examples to Racket. Perhaps you
could start with the Python code that works as you expect, port it to
Racket, then refactor it to more Rackety ways:
http://hg.python.org/cpython/file/cc0e72082e52/Lib/json


On Tue, Apr 16, 2013 at 1:54 PM, Eli Barzilay <eli at barzilay.org> wrote:

> Just now, Nick Shelley wrote:
> > In talking with an experienced Racketeer, I realized that
> > pretty-print has a specific meaning in Racket that takes width into
> > account.
>
> That's exactly what I thought you were talking about.  Doing it from
> scratch seems wrong, and I thought that the right way to do it is to
> hook into the pretty-printer that we already have.
>
>
> > What I really want is json with properly placed newlines and tabs
> > (or spaces).
>
> This sounds somewhere between very easy (if all you want is
> newlines+indentation up to a specific level) to something more
> complicated if you want to control other aspects like spaces around
> colons, sort keys in tables, etc.
>
>
> > I'm willing to take a stab at it if it doesn't exist. I just wanted
> > to make sure I wasn't missing it somewhere (which happens often with
> > me).
>
> If you can summarize the python-equivalent features in a rackety way,
> I can see if it's easy to add them to our printer.
>
> IIUC, this interface means that `write-json' would get a bunch of
> additional keywords, but I'm not sure about it, since in Racket
> `write' usually refers to something closer to serializing a value in a
> readable way rather than printing it in a readable way.  So maybe the
> right thing is to add a `print-json' function even if it duplicates
> the functionality of `write-json'.
>
> --
>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                     http://barzilay.org/                   Maze is Life!
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130416/95a34e1a/attachment.html>

Posted on the users mailing list.