5 ms·
Please: { "colors": [ { "color": "black", "hex": "#000", "rgb": [ 0, 0, 0 ] }, { "color": "red", "hex": "#f00", "rgb": [
by thechao 6y ago
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 ] }
]
}
- peterohler 6y agoAn issue has been added to the repo. It is on the list now. Great idea, thanks. https://github.com/ohler55/ojg/issues/35 https://github.com/ohler55/ojg/issues/35
- falcolas 6y agoOpinionated 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.
- j-krieger 6y agoJust 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"}", ... }
- ajuc 6y agoThat's the point GP is making. Use JSON objects for dictionary-like structures instead of directly translating XML to JSON.
- SamBam 6y agoBut 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.)
- falcolas 6y ago> 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.
- falcolas 6y agoIt's absolutely possible, yet the example doesn't do it. That's what the comment was calling out (plus a bit of superfluous "WTF").
- remram 6y agoWhat 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.
- falcolas 6y agoThen 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.
- remram 6y agoYou 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.
- leoedin 6y agoI 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.
- falcolas 6y agoIt 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.
- zeroimpl 6y agoPerhaps 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.
- d0mine 6y agovisidata 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.
- Latty 6y agoPersonally, aligning columns like that drives me nuts. It's awkward to maintain and makes things harder to actually read most of the time.
- jng 6y agoHow 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.
- augusto-moura 6y agoThe 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 ] } ] }
- deleted 6y ago[deleted]
- Zecc 6y ago> 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 ] } ] }
- mschuetz 6y agoYou 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 ] }, ] }
- ivanche 6y agoOuch! This is borderline unreadable to me. Even more so when there's a value of length, say, 50 for the one of color keys.
- stouset 6y agoWhat on earth is difficult to read about aligned data? More importantly, what’s more readable to you?
- ivanche 6y agoGinormous 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.