[racket] Json pretty-print
First off, thanks Carl and Danny for the code. The thing is, the system
call to python works for our needs and is easier than rolling my own. The
reason I started this thread in the first place is because it seems like
outputting human-readable json is common and often desired (see the upvotes
in the SO article in the second message for proof). Because it seems so
common, I just assumed I was missing something. When I found out it was
missing from the Racket json module, I thought it would be more complete
with this functionality. I'm now seeing that there are many different uses
and desires and design choices that need to be made, so what functionality
to provide isn't as clear as I thought (I'm not sure what development
process the other libraries went through for the human-readable option).
I still would like to see this functionality in the Racket json library,
but since the Python thing works for now, my reasons are mainly to save
face with my coworker and to avoid repeating this process if I ever think I
need human-readable json in the future and want to use Racket. I also
thought it might be cool to make a contribution, but seeing the code
provided above, I'm thinking I may not be as qualified as I thought.
My following responses should be taken in that context:
Eli Barzilay wrote:
> If the goal is just diffing, then it makes things a little different:
> you'll want newlines, and you won't care about indentation.
The goal is to have human-readable json mainly for the purpose of making
diffing easier. Our data is a nested hierarchy, and I would argue that
indentation makes it more readable by humans. I agree that it's not
completely necessary for diffing, but it does help visualize hierarchy
depth, which may be part of what's different.
> But a better solution would be to find a diff tool that works on the line,
> or even better a tree diff thing...
More specifically, this json file is part of project in a git repository,
and we use gerrit (https://code.google.com/p/gerrit/) for code reviews.
Large one-line diffs are hard to make sense of, and gerrit only allows
comments at the line level.
Danny Yoo wrote:
> I think the point is: it should be very easy to do this; it's just a
> matter of knowing what behavior you want.
We used to have an Objective-C project with all the data hard-coded and
written to json when we wanted, but I couldn't stand editing that beast any
more, so I made a Racket command-line tool to read in the json and process
commands to edit it in ways we need. I would have just switched to a
database, but the json representation is a sanity check to make sure I
didn't do anything stupid (and also for others to verify that in gerrit),
hence the need to have it human readable.
I assume we'll eventually go to some neat UI or web interface or something,
but that probably won't happen for a while. I give you that context because
I think it makes the desired behavior clearer than me trying to describe
it, and it also gives you the chance to tell me what I should want.
On Tue, Apr 16, 2013 at 1:32 PM, Eli Barzilay <eli at barzilay.org> wrote:
> That's not really relevant in this case: there is no problem here
> comparing the keys since they are all symbols.
>
>
> 10 minutes ago, Danny Yoo wrote:
> > Racket provides a generic order predicate: see data/order:
> >
> >
> http://docs.racket-lang.org/data/Orders_and_Ordered_Dictionaries.html
> >
> > For example,
> >
> > https://gist.github.com/dyoo/5398549#file-pretty-print-json-rkt-L5
> > https://gist.github.com/dyoo/5398549#file-pretty-print-json-rkt-L12
> > https://gist.github.com/dyoo/5398549#file-pretty-print-json-rkt-L12
>
> --
> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
> http://barzilay.org/ Maze is Life!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130416/3e2134a5/attachment-0001.html>