Live data from Hacker News

The Pretty JSON Revolution

ohler.com

131–140 of 159 posts

Re: The Pretty JSON Revolution

#132
post #89

Earlier quoted context omitted.

> The position of commas in the rgb array are triggering me You mean: { "colors": [ { "color": "black" , "hex": "#000", "rgb": [ 0, 0, 0 ] }, { "color": "red" , "hex": "#f00", "rgb": [ 255, 0, 0 ] }, { "color": "yellow" , "hex": "#ff0", "rgb": [ 255, 255, 0 ] }, { "color": "green" , "hex": "#0f0", "rgb": [ 0, 255, 0 ] }, { "color": "cyan" , "hex": "#0ff", "rgb": [ 0, 255, 255 ] }, { "color": "blue" , "hex": "#00f", "…

You mean: { "colors": [ { "color": "black" , "hex": "#000", "rgb": [ 0, 0, 0 ] }, { "color": "red" , "hex": "#f00", "rgb": [ 255, 0, 0 ] }, { "color": "yellow" , "hex": "#ff0", "rgb": [ 255, 255, 0 ] }, { "color": "green" , "hex": "#0f0", "rgb": [ 0, 255, 0 ] }, { "color": "cyan" , "hex": "#0ff", "rgb": [ 0, 255, 255 ] }, { "color": "blue" , "hex": "#00f", "rgb": [ 0, 0, 255 ] }, { "color": "magenta", "hex": "#f0f",…

[deleted]

Re: The Pretty JSON Revolution

#133

Earlier quoted context omitted.

The other spec (ECMA-404) disagrees with RFC 7159 on this point. That's the great thing about specs -- if you don't like what one says, there's always another to support your position. :)

That ECMA (via ECMA-404) and IETF (via RFC 8259, and before that RFC 7159) have subtly incompatible standards with the same title is annoying; perhaps we need to talk about “IETF JSON” (or “application/json”, as it is expressly the basis of the MIME type) vs “ECMA JSON”.

Here is our opportunity to publish an ANSI or ISO spec, and take the market by storm. :)

Personally, I will adopt the first version of JSON that lets me insert a flipping comment!

Re: The Pretty JSON Revolution

#134
post #126
post #89

Earlier quoted context omitted.

> The position of commas in the rgb array are triggering me You mean: { "colors": [ { "color": "black" , "hex": "#000", "rgb": [ 0, 0, 0 ] }, { "color": "red" , "hex": "#f00", "rgb": [ 255, 0, 0 ] }, { "color": "yellow" , "hex": "#ff0", "rgb": [ 255, 255, 0 ] }, { "color": "green" , "hex": "#0f0", "rgb": [ 0, 255, 0 ] }, { "color": "cyan" , "hex": "#0ff", "rgb": [ 0, 255, 255 ] }, { "color": "blue" , "hex": "#00f", "…

Exactly. I format things like that in my source code. Anything else is too painful to bear. When code by other people who don't care about those things, it's hard to understand :)

And then somebody wants to edit the file your careful alignment gets gradually mangled and there's no tooling to auto-do it and we refactor something globally and it gets worse and ultimately I go shift-alt-F to restore it to autoformatted sanity.

Re: The Pretty JSON Revolution

#135
post #84

Relevant plug: if Pretty Notations interest you, then you should keep an eye on Tree Notation https://treenotation.org/ .

The Tree Notation is like the opposite of pretty notation though, no?

The whole idea of pretty notation is automatically inserting non-significant whitespace to make it look nice. Step 2, "one line per node", inserts spaces and newlines. Step 4, "human style" strategically removes some of those so the lines look nice -- the 2nd level dict has lots of content, so it was split across multiple lines... while the 3rd level dict has fewer data, so it all fits on one line.

As opposed to this, Tree Notation is all about single canonical representation. So whitespace is significant, and you can never add or remove it to make output look nicer. You do whatever your schema tells you, and I hope you like many short lines.

Re: The Pretty JSON Revolution

#136

It seems a mistake to format JSON as non-JSON text (SEN Format) in the name of "pretty". That will inevitably lead to copy/paste and monkey-see errors.

I think that even you discard the last step ("sen") and stick to plain "human style with colors", this is already much prettier than many languages support.

I like the idea that the incompatible format is off by default.

Re: The Pretty JSON Revolution

#137
post #9

In addition to outputting HTML, it could output JSON that could be rendered to HTML, the terminal, or JSX: https://github.com/wooorm/lowlight#projects

oo cool, wooorm looks useful, thanks for the link

You're not wrong, but wooorm is a person.

Remark and Unified are some well-known projects that wooorm maintains.

https://github.com/remarkjs/remark https://unifiedjs.com/

Re: The Pretty JSON Revolution

#138
post #8
post #3

If you're on a mac or Linux system, you likely have a JSON formatter already installed `python3 -m json.tool somefile.json` or `cat foo.json | python3 -m json.tool` will print it in "one line per node" format. 3.9 introduces a --sort-keys switch for sorted objects also.

I did not know about sort keys. I'm adding that to my alias. Thank you.

Oj supports a config file as well. .oj-config.sen. -help-config will describe it in more detail.

Re: The Pretty JSON Revolution

#139

Earlier quoted context omitted.

oo cool, wooorm looks useful, thanks for the link

You're not wrong, but wooorm is a person. Remark and Unified are some well-known projects that wooorm maintains. https://github.com/remarkjs/remark https://unifiedjs.com/

hahaha (facepalm) I use remark, too. Sorry wooorm!

Re: The Pretty JSON Revolution

#140

Earlier quoted context omitted.

> The JSON language spec has ORDERED object members. False. “An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.” [emphasis added][0] [0] https://tools.ietf.org/html/rfc8259

Not exactly, unfortunately. The text you cite is in the introduction, which is non-normative. That text talks about the conceptual data model, but that's just to frame the reader's thinking. The normative text has the "real" answer, and the real answer is that it's basically undefined behavior. It starts by saying "The names within an object SHOULD be unique", and then elaborates: An object whose names are all unique…

So basically, "it's a free-for-all, we guarantee absolutely nothing unless you 1) don't generate duplicate keys and 2) the code of your consumer doesn't depend on their ordering".
Post reply on HN