Click here to Skip to main content
15,879,095 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 1:30
mveRickZeeland13-Dec-20 1:30 
GeneralRe: Worst website design of 2020 competition ... Pin
dandy7218-Dec-20 10:26
dandy7218-Dec-20 10:26 
GeneralRe: Worst website design of 2020 competition ... Pin
theoldfool13-Dec-20 3:41
professionaltheoldfool13-Dec-20 3:41 
GeneralOi! honey the codewitch! Pin
OriginalGriff12-Dec-20 20:02
mveOriginalGriff12-Dec-20 20:02 
GeneralRe: Oi! honey the codewitch! Pin
honey the codewitch12-Dec-20 23:11
mvahoney the codewitch12-Dec-20 23:11 
GeneralRe: Oi! honey the codewitch! Pin
Sander Rossel13-Dec-20 1:05
professionalSander Rossel13-Dec-20 1:05 
GeneralRe: Oi! honey the codewitch! Pin
honey the codewitch13-Dec-20 2:02
mvahoney the codewitch13-Dec-20 2:02 
GeneralJSON is almost perfect, except... Pin
honey the codewitch12-Dec-20 16:47
mvahoney the codewitch12-Dec-20 16: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 19:05
professionalBillWoodruff12-Dec-20 19:05 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch12-Dec-20 23:06
mvahoney the codewitch12-Dec-20 23:06 
GeneralRe: JSON is almost perfect, except... Pin
trønderen12-Dec-20 19:28
trønderen12-Dec-20 19:28 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch12-Dec-20 23:07
mvahoney the codewitch12-Dec-20 23:07 
GeneralRe: JSON is almost perfect, except... Pin
Greg Utas13-Dec-20 1:29
professionalGreg Utas13-Dec-20 1:29 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 2:03
mvahoney the codewitch13-Dec-20 2:03 
GeneralRe: JSON is almost perfect, except... Pin
Greg Utas13-Dec-20 2:05
professionalGreg Utas13-Dec-20 2:05 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 2:10
mvahoney the codewitch13-Dec-20 2:10 
GeneralRe: JSON is almost perfect, except... Pin
Gerry Schmitz13-Dec-20 6:01
mveGerry Schmitz13-Dec-20 6:01 
GeneralRe: JSON is almost perfect, except... Pin
PIEBALDconsult13-Dec-20 6:47
mvePIEBALDconsult13-Dec-20 6:47 
GeneralRe: JSON is almost perfect, except... Pin
PIEBALDconsult13-Dec-20 6:41
mvePIEBALDconsult13-Dec-20 6:41 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch13-Dec-20 7:07
mvahoney the codewitch13-Dec-20 7:07 
GeneralRe: JSON is almost perfect, except... Pin
Jörgen Andersson13-Dec-20 20:27
professionalJörgen Andersson13-Dec-20 20:27 
GeneralRe: JSON is almost perfect, except... Pin
honey the codewitch14-Dec-20 1:30
mvahoney the codewitch14-Dec-20 1:30 
GeneralRe: JSON is almost perfect, except... Pin
Jörgen Andersson14-Dec-20 1:37
professionalJörgen Andersson14-Dec-20 1:37 
GeneralRIP Charley Pride Pin
Cp-Coder12-Dec-20 12:44
Cp-Coder12-Dec-20 12:44 
GeneralWhen you're very clever you are really stupid Pin
Cp-Coder12-Dec-20 8:06
Cp-Coder12-Dec-20 8: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.