News for hackers. Stuff that matters.
Re:The Pretty JSON Revolution by thechao on Tuesday February 23, 2021 @10:12AM (#26238150)
Please:

    {
      "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", "rgb": [ 255, 0,   255 ] },
        { "color": "white",   "hex": "#fff", "rgb": [ 255, 255, 255 ] }
      ]
    }
Re:The Pretty JSON Revolution by augusto-moura on Tuesday February 23, 2021 @11:26AM (#26239171)
The position of commas in the rgb array are triggering me

Numbers to the right make it much more pleasant to my eyes

    {
      "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", "rgb": [ 255,   0, 255 ] },
        { "color": "white",   "hex": "#fff", "rgb": [ 255, 255, 255 ] }
      ]
    }
Re:The Pretty JSON Revolution by Zecc on Tuesday February 23, 2021 @11:40AM (#26239365)
> 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", "rgb": [   0,   0, 255 ] },
        { "color": "magenta", "hex": "#f0f", "rgb": [ 255,   0, 255 ] },
        { "color": "white"  , "hex": "#fff", "rgb": [ 255, 255, 255 ] }
      ]
    }
Re:The Pretty JSON Revolution by mschuetz on Tuesday February 23, 2021 @01:51PM (#26241190)
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", "rgb": [ 255,   0, 255 ] },
        { "color": "white"  , "hex": "#fff", "rgb": [ 255, 255, 255 ] },
      ]
    }
Re:The Pretty JSON Revolution by jng on Tuesday February 23, 2021 @02:52PM (#26242018)
The last extra comma is valid javascript, but, (possibly) unfortunately, invalid JSON.
Re:The Pretty JSON Revolution by jng on Tuesday February 23, 2021 @02:53PM (#26242037)
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 :)
Re:The Pretty JSON Revolution by Pxtl on Tuesday February 23, 2021 @04:02PM (#26242856)
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 by falcolas on Tuesday February 23, 2021 @10:26AM (#26238339)
Opinionated Opinion:

That's an incredibly XML-ified version of a color table. I can clearly see the tags now. Can't just do a look up of a color color, instead I would have to iterate over the members or store it in a different data structure.

Why even use JSON? Blech.

Re:The Pretty JSON Revolution by j-krieger on Tuesday February 23, 2021 @10:31AM (#26238409)
Just because the data is structured this way in the example, doesn't mean it's not possible. What's hindering you from defining a class property for each color?

"colors": { "red":{"rgb":"fff"}", ... }

Re:The Pretty JSON Revolution by falcolas on Tuesday February 23, 2021 @10:38AM (#26238490)
It's absolutely possible, yet the example doesn't do it. That's what the comment was calling out (plus a bit of superfluous "WTF").
Re:The Pretty JSON Revolution by remram on Tuesday February 23, 2021 @10:58AM (#26238766)
What if you want to get the name for a hex color? Your "opinion" is just assumptions on how the data structure will be used, which you want to bake into the transmission format itself.
Re:The Pretty JSON Revolution by falcolas on Tuesday February 23, 2021 @11:08AM (#26238926)
Then you're no worse off than if you had the original format. You'd have to iterate through the members in either case.

That said, given there are just shy of 17 million possible RBG combinations, and a small fraction those are of named colors, I'd personally continue to optimize for the named color case.

Re:The Pretty JSON Revolution by remram on Tuesday February 23, 2021 @12:39PM (#26240207)
You should definitely optimize your data storage for the kind of operations you're going to do on them. However you're taking about the data transmission format here!

Surely you wouldn't think of sending a piece of JSON over the wire with both name:color and rgb:color, regardless of whether that is what the recipient wants to operate on. You just have to let it unmarshall the data into whatever form it needs.

Re:The Pretty JSON Revolution by ajuc on Tuesday February 23, 2021 @10:37AM (#26238479)
That's the point GP is making. Use JSON objects for dictionary-like structures instead of directly translating XML to JSON.
Re:The Pretty JSON Revolution by SamBam on Tuesday February 23, 2021 @11:05AM (#26238873)
But the point is that it's always usage dependant.

You key by color names, that seems obvious. But what if you want to look up a color by hex? Now you have to look through them all.

What if this list is actually an order list of colors for different headings? And they can repeat? Then indexing by index is exactly what you want.

Point is, you don't know the reason behind the data structure.

(That said, I do wish the json had a standardized way to remove redundancy for objects that always follow the same structure. One list of property names, and then everything in arrays.)

Re:The Pretty JSON Revolution by falcolas on Tuesday February 23, 2021 @11:15AM (#26239024)
> But what if you want to look up a color by hex? Now you have to look through them all.

As you would with the original one as well.

> Then indexing by index is exactly what you want.

A much better use case. That said, the list order is kinda fragile, having an explicit row identifier might be worth adding. Especially since all of the columns are being explicitly called out instead of in their own list.

Re:The Pretty JSON Revolution by zeroimpl on Tuesday February 23, 2021 @06:05PM (#26244238)
Perhaps the purpose is to list colors in a specific order, such as to show to the user in a desired order?

And before you argue that dictionaries can still be iterated in order, you better check the sibling threads where people are arguing you shouldn’t rely on that.

Re:The Pretty JSON Revolution by leoedin on Tuesday February 23, 2021 @11:17AM (#26239045)
I don't get why you're railing against this comment - that's the same data structure used in the article we're discussing. The only difference between the proposal in the grandparent comment and the article is the indentation and spacing.
Re:The Pretty JSON Revolution by falcolas on Tuesday February 23, 2021 @11:20AM (#26239078)
It being the same structure doesn't make it good.

That said, my comment may a bit misdirected as a result, in which case: Mea Culpa.

Re:The Pretty JSON Revolution by peterohler on Tuesday February 23, 2021 @10:18AM (#26238227)
An issue has been added to the repo. It is on the list now. Great idea, thanks. https://github.com/ohler55/ojg/issues/35
Re:The Pretty JSON Revolution by Latty on Tuesday February 23, 2021 @11:09AM (#26238937)
Personally, aligning columns like that drives me nuts. It's awkward to maintain and makes things harder to actually read most of the time.
Re:The Pretty JSON Revolution by jng on Tuesday February 23, 2021 @02:54PM (#26242060)
How does it make it harder to read? Patterns and repetitions jump out of the page. Indeed, maintaining it takes time and effort, I wish the editor were smart enough, but I only see advantages with regards to reading the code.
Re:The Pretty JSON Revolution by d0mine on Tuesday February 23, 2021 @10:45AM (#26238591)
visidata shows it as:

  color   | hex  | rgb ║
  red     | #f00 | [3] ║
  black   | #000 | [3] ║
  yellow  | #ff0 | [3] ║
  green   | #0f0 | [3] ║
  cyan    | #0ff | [3] ║
  blue    | #00f | [3] ║
  magenta | #f0f | [3] ║
  white   | #fff | [3] ║
I would be nice to inline the rgb column here.
Re:The Pretty JSON Revolution by ivanche on Tuesday February 23, 2021 @11:41AM (#26239382)
Ouch! This is borderline unreadable to me. Even more so when there's a value of length, say, 50 for the one of color keys.
Re:The Pretty JSON Revolution by stouset on Tuesday February 23, 2021 @01:16PM (#26240631)
What on earth is difficult to read about aligned data?

More importantly, what’s more readable to you?

Re:The Pretty JSON Revolution by ivanche on Wednesday February 24, 2021 @05:09AM (#26248425)
Ginormous distances between values and keys. It's enough to have just 2-3 long values in 2-3 different rows and the amount of whitespace becomes huge, much larger than the amount of data.