Click here to Skip to main content
15,113,726 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Worst website design of 2020 competition ... Pin
RickZeeland13-Dec-20 2:30
mveRickZeeland13-Dec-20 2:30 
GeneralRe: Worst website design of 2020 competition ... Pin
dandy7218-Dec-20 11:26
Memberdandy7218-Dec-20 11:26 
GeneralRe: Worst website design of 2020 competition ... Pin
theoldfool13-Dec-20 4:41
professionaltheoldfool13-Dec-20 4:41 
GeneralOi! honey the codewitch! Pin
OriginalGriff12-Dec-20 21:02
mveOriginalGriff12-Dec-20 21:02 
GeneralRe: Oi! honey the codewitch! Pin
honey the codewitch13-Dec-20 0:11
mvahoney the codewitch13-Dec-20 0:11 
GeneralRe: Oi! honey the codewitch! Pin
Sander Rossel13-Dec-20 2:05
professionalSander Rossel13-Dec-20 2:05 
GeneralRe: Oi! honey the codewitch! Pin
honey the codewitch13-Dec-20 3:02
mvahoney the codewitch13-Dec-20 3:02 
GeneralJSON is almost perfect, except... Pin
honey the codewitch12-Dec-20 17:47
mvahoney the codewitch12-Dec-20 17:47 
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:
JavaScript
{
  "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?
C++
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.
C++
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.

Sigh | :sigh:

JSON is deceptively complicated.
Real programmers use butterflies

GeneralRe: JSON is almost perfect, except... Pin
BillWoodruff12-Dec-20 20:05
mveBillWoodruff12-Dec-20 20:05 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 0:06
mvahoney the codewitch13-Dec-20 0:06 
GeneralRe: JSON is almost perfect, except... Pin
trønderen12-Dec-20 20:28
Membertrønderen12-Dec-20 20:28 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 0:07
mvahoney the codewitch13-Dec-20 0:07 
GeneralRe: JSON is almost perfect, except... Pin
Greg Utas13-Dec-20 2:29
mvaGreg Utas13-Dec-20 2:29 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 3:03
mvahoney the codewitch13-Dec-20 3:03 
GeneralRe: JSON is almost perfect, except... Pin
Greg Utas13-Dec-20 3:05
mvaGreg Utas13-Dec-20 3:05 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 3:10
mvahoney the codewitch13-Dec-20 3:10 
GeneralRe: JSON is almost perfect, except... Pin
Gerry Schmitz13-Dec-20 7:01
mveGerry Schmitz13-Dec-20 7:01 
GeneralRe: JSON is almost perfect, except... Pin
PIEBALDconsult13-Dec-20 7:47
professionalPIEBALDconsult13-Dec-20 7:47 
GeneralRe: JSON is almost perfect, except... Pin
PIEBALDconsult13-Dec-20 7:41
professionalPIEBALDconsult13-Dec-20 7:41 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 8:07
mvahoney the codewitch13-Dec-20 8:07 
GeneralRe: JSON is almost perfect, except... Pin
Jörgen Andersson13-Dec-20 21:27
professionalJörgen Andersson13-Dec-20 21:27 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch14-Dec-20 2:30
mvahoney the codewitch14-Dec-20 2:30 
GeneralRe: JSON is almost perfect, except... Pin
Jörgen Andersson14-Dec-20 2:37
professionalJörgen Andersson14-Dec-20 2:37 
GeneralRIP Charley Pride Pin
Cp-Coder12-Dec-20 13:44
MemberCp-Coder12-Dec-20 13:44 
GeneralWhen you're very clever you are really stupid Pin
Cp-Coder12-Dec-20 9:06
MemberCp-Coder12-Dec-20 9:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.