MCPcopy Create free account
hub / github.com/apache/cloudberry / parse_object_field

Function parse_object_field

src/common/jsonapi.c:316–367  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316static JsonParseErrorType
317parse_object_field(JsonLexContext *lex, JsonSemAction *sem)
318{
319 /*
320 * An object field is "fieldname" : value where value can be a scalar,
321 * object or array. Note: in user-facing docs and error messages, we
322 * generally call a field name a "key".
323 */
324
325 char *fname = NULL; /* keep compiler quiet */
326 json_ofield_action ostart = sem->object_field_start;
327 json_ofield_action oend = sem->object_field_end;
328 bool isnull;
329 JsonTokenType tok;
330 JsonParseErrorType result;
331
332 if (lex_peek(lex) != JSON_TOKEN_STRING)
333 return report_parse_error(JSON_PARSE_STRING, lex);
334 if ((ostart != NULL || oend != NULL) && lex->strval != NULL)
335 fname = pstrdup(lex->strval->data);
336 result = json_lex(lex);
337 if (result != JSON_SUCCESS)
338 return result;
339
340 result = lex_expect(JSON_PARSE_OBJECT_LABEL, lex, JSON_TOKEN_COLON);
341 if (result != JSON_SUCCESS)
342 return result;
343
344 tok = lex_peek(lex);
345 isnull = tok == JSON_TOKEN_NULL;
346
347 if (ostart != NULL)
348 (*ostart) (sem->semstate, fname, isnull);
349
350 switch (tok)
351 {
352 case JSON_TOKEN_OBJECT_START:
353 result = parse_object(lex, sem);
354 break;
355 case JSON_TOKEN_ARRAY_START:
356 result = parse_array(lex, sem);
357 break;
358 default:
359 result = parse_scalar(lex, sem);
360 }
361 if (result != JSON_SUCCESS)
362 return result;
363
364 if (oend != NULL)
365 (*oend) (sem->semstate, fname, isnull);
366 return JSON_SUCCESS;
367}
368
369static JsonParseErrorType
370parse_object(JsonLexContext *lex, JsonSemAction *sem)

Callers 1

parse_objectFunction · 0.85

Calls 8

lex_peekFunction · 0.85
report_parse_errorFunction · 0.85
json_lexFunction · 0.85
lex_expectFunction · 0.85
parse_objectFunction · 0.85
parse_arrayFunction · 0.85
parse_scalarFunction · 0.85
pstrdupFunction · 0.70

Tested by

no test coverage detected