News for hackers. Stuff that matters.
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.