Skip to content

Commit de0f9e3

Browse files
author
Nikita Glukhov
committed
Add JsonGetObjectSize()
1 parent a08ce90 commit de0f9e3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/backend/utils/adt/json_generic.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,27 @@ jsonGetArraySize(JsonContainer *array)
280280
return size;
281281
}
282282

283+
uint32
284+
JsonGetObjectSize(JsonContainer *object)
285+
{
286+
JsonValue val;
287+
JsonIterator *it;
288+
JsonIteratorToken tok;
289+
uint32 size = 0;
290+
291+
Assert(JsonContainerIsObject(object));
292+
293+
it = JsonIteratorInit(object);
294+
295+
while ((tok = JsonIteratorNext(&it, &val, true)) != WJB_DONE)
296+
{
297+
if (tok == WJB_KEY)
298+
size++;
299+
}
300+
301+
return size;
302+
}
303+
283304
static void
284305
jsonvInitContainer(JsonContainerData *jc, const JsonValue *val)
285306
{

src/include/utils/json_generic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ extern JsonValue *jsonFindLastKeyInObject(JsonContainer *obj, const JsonValue
507507
extern JsonValue *jsonFindValueInArray(JsonContainer *array, const JsonValue *elem);
508508
extern uint32 jsonGetArraySize(JsonContainer *array);
509509
extern JsonValue *jsonGetArrayElement(JsonContainer *array, uint32 index);
510+
extern uint32 JsonGetObjectSize(JsonContainer *object);
510511

511512
extern bool JsonValueScalarEquals(const JsonValue *aScalar,
512513
const JsonValue *bScalar);

0 commit comments

Comments
 (0)