|
@code-witch
Congratulations on your "Article of the month" win for last month! Well deserved!
Keep 'em coming.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks!
Real programmers use butterflies
|
|
|
|
|
Congrats, you legend! Which one was it?
|
|
|
|
|
|
JSON "object" fields can be in any order. They are not guaranteed to be in "schema order" or alphabetical/asciibetical order.
This makes it very difficult to query a JSON object without loading it into memory first.
Consider the following JSON:
{
"air_date": "2011-04-17",
"episode_number": 1,
"id": 224659,
"name": "The Fall of Sam Axe",
"overview": "The Fall of Sam Axe is a 2011 American television film based on the USA Network television series Burn Notice...",
"production_code": null,
"season_number": 0,
"show_id": 2919
}
Say I wanted to format a string like "S00E01 The Fall of Sam Axe"
Easy, right?
printf("S%02dE%02d %s\r\n",season_number,episode_number,name);
Where the three format vars come from the JSON fields of the same name.
The trouble is this: I don't know which order the fields come in. I can see they're alphabetical now, but the spec says I can't count on that.
So if I'm using a streaming pull parser over a forward only cursor I've got a bit of a problem.
One solution is to have the parser be able to skip to a field with a set of possible field names.
const char* fields[] = {"season_number","episode_number","name"};
while(jsonReader.skipToFields(fields,3,JsonReader::Siblings)) {
...
}
The trouble is implementing skipToFields() is extremely difficult because of the varying starting points. What happens in that while loop dictates where your cursor ends up, and finding the next fields from that is no joke. I don't keep a depth because certain operations like using the "All" axis cut right through the hierarchy and those searching/skipping functions only do partial parsing.
JSON is deceptively complicated.
Real programmers use butterflies
|
|
|
|
|
Please use QA to ask specific technical questions.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
That would be great, if I was asking a question. I'll look for the question mark in my post which I clearly put in there by mistake.
Real programmers use butterflies
|
|
|
|
|
I'd say that JSON is suitable in environments where reading the structure into memory is The Thing To Do.
If you cannot read the whole thing into memory, maybe JSON isn't for you
This, of course, assumes that JSON is suitable at all.
But for a general comment: The very idea of a tagged record structure is to be independent of ordering. If the ordering where fixed according to some schema, an array would probably be a better choice. Then you could omit the tags altogether, saving both space and processing.
|
|
|
|
|
trønderen wrote: If you cannot read the whole thing into memory, maybe JSON isn't for you
The entire world of IoT would scarcely exist online if that were the case.
Real programmers use butterflies
|
|
|
|
|
...and that might not be such a bad thing.
|
|
|
|
|
I'd be out of work.
Real programmers use butterflies
|
|
|
|
|
Somehow I imagine you could easily find something else!
|
|
|
|
|
But something I enjoy this much?
My core nature is not "software developer"
It's "builder"
I like to make things. The reason I got into software is when I was very young I was building simple digital circuits but i didn't have money to buy the neverending list of equipment and supplies to keep up the hobby, so I got into software, which required nothing upfront (at the time) but effort. I fell in love with it and just never stopped.
But ultimately I like to build. Under slightly different circumstances I could have been a metal fabricator and/or engineer.
The IoT stuff incorporates some of that physicality that I like.
Real programmers use butterflies
|
|
|
|
|
They're "key value pairs" ... no order implied. XML has paths. That's why XML is "more perfect".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
XML also does not impose order.
|
|
|
|
|
Well, obviously the user should be responsible for specifying the order of the desired fields and not you.
|
|
|
|
|
With JSON *nobody* gets to specify the order. That makes them suitable for putting in things like std::unordered_map, but not so great for sequential forward only queries.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: JSON is deceptively complicated.
Only because you're not using it as intended.
There's nothing that stops you from defining a new ordered JSON-standard. I mean, another standard is just what we need isn't it.
Wrong is evil and must be defeated. - Jeff Ello
Never stop dreaming - Freddie Kruger
|
|
|
|
|
I mean, I don't know that JSON wasn't *intended* for low memory environments, but I could get behind the idea that it wasn't designed for them.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: but I could get behind the idea that it wasn't designed for them
Fair enough.
I see it this way, JSON was intended to be used with Javascript. Javascript is anything but low memory! Intentional or not.
Wrong is evil and must be defeated. - Jeff Ello
Never stop dreaming - Freddie Kruger
|
|
|
|
|
|
Herself asked me to play some Christmas music in the background. We have a Yamaha sound bar under the TV that can be set to use Bluetooth as its sound input. So I thought it would great to send music from my laptop to the sound bar, as its sound quality is fantastic.
I must have tried for more than an hour to get the two devices to connect via Bluetooth, with no luck. In the end in sheer desperation, I decided to read the Yamaha manual - and there it was plain as day: If you have difficulty to connect, you may have another Bluetooth device too close to the sound bar. Yes! I turned off my desktop's (which was nearby) Bluetooth and the sound bar immediately connected to the laptop. Aaaaargh!
So she asked me why I did not read the manual in the first place? I said: "I am an engineer, I shouldn't have to read manuals."
She said: "For a clever engineer you are rather stupid!" So here I sit listening to Christmas music with a deflated ego!
Get me coffee and no one gets hurt!
modified 12-Dec-20 14:18pm.
|
|
|
|
|
For something a bit different, try John Fahey's Christmas music played on guitar : https://www.amazon.com/s?k=john+fahey&ref=nb_sb_noss_1[^]. It's really very, very good if you like acoustic guitar music.
A piece of trivia : in the movie "A Clockwork Orange", Alex goes into a record store and at the counter there are two albums displayed. One is the soundtrack of "2001, A Space Odyssey" and the other is a John Fahey record.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
Thanks! I'll check it out.
Get me coffee and no one gets hurt!
|
|
|
|
|
I could't see any preview (or pre-listen) on Amazon, but I'll take one note of the name, and try to find a preview somehwere else.
One of my primary Christmas record is another acoustic guitar one - Jul I Gammel Tid by Rolf Lislevand[^] ("Chistmas on the old days").
In this case it is somewhat unfortunate that Amazon tends to pick their 30 sec samples from the start, or early part, of the track. That is when the theme is introduced, and you do not get an opportunity to hear how the player elaborates on it, makes his variations, plays around it, the way old musicians did. A few of the tracks chains together two or three tunes in a beautiful way, that you will not get a chance to hear (without buying the album).
Lislevand may be the very best baroque guitar player of today, knowing more about the historically "correct" interpretation than most others. Yet, he is very playful: Listen to the way his group goes completely crazy with old "Tourdion" on the album "Diminitio"! (Here, the first 30 seconds reveal none of the crazyness )
|
|
|
|