@@ -479,6 +479,40 @@ flattenJsonPathParseItem(JsonPathEncodingContext *cxt, JsonPathParseItem *item,
479479 }
480480 }
481481 break ;
482+ case jpiObject :
483+ {
484+ int32 nfields = list_length (item -> value .object .fields );
485+ ListCell * lc ;
486+ int offset ;
487+
488+ checkJsonPathExtensionsEnabled (cxt , item -> type );
489+
490+ appendBinaryStringInfo (buf , (char * ) & nfields , sizeof (nfields ));
491+
492+ offset = buf -> len ;
493+
494+ appendStringInfoSpaces (buf , sizeof (int32 ) * 2 * nfields );
495+
496+ foreach (lc , item -> value .object .fields )
497+ {
498+ JsonPathParseItem * field = lfirst (lc );
499+ int32 keypos =
500+ flattenJsonPathParseItem (cxt , field -> value .args .left ,
501+ nestingLevel ,
502+ insideArraySubscript );
503+ int32 valpos =
504+ flattenJsonPathParseItem (cxt , field -> value .args .right ,
505+ nestingLevel ,
506+ insideArraySubscript );
507+ int32 * ppos = (int32 * ) & buf -> data [offset ];
508+
509+ ppos [0 ] = keypos - pos ;
510+ ppos [1 ] = valpos - pos ;
511+
512+ offset += 2 * sizeof (int32 );
513+ }
514+ }
515+ break ;
482516 default :
483517 elog (ERROR , "unrecognized jsonpath item type: %d" , item -> type );
484518 }
@@ -795,6 +829,26 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
795829 }
796830 appendStringInfoChar (buf , ']' );
797831 break ;
832+ case jpiObject :
833+ appendStringInfoChar (buf , '{' );
834+
835+ for (i = 0 ; i < v -> content .object .nfields ; i ++ )
836+ {
837+ JsonPathItem key ;
838+ JsonPathItem val ;
839+
840+ jspGetObjectField (v , i , & key , & val );
841+
842+ if (i )
843+ appendBinaryStringInfo (buf , ", " , 2 );
844+
845+ printJsonPathItem (buf , & key , false, false);
846+ appendBinaryStringInfo (buf , ": " , 2 );
847+ printJsonPathItem (buf , & val , false, val .type == jpiSequence );
848+ }
849+
850+ appendStringInfoChar (buf , '}' );
851+ break ;
798852 default :
799853 elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
800854 }
@@ -1011,6 +1065,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
10111065 read_int32_n (v -> content .sequence .elems , base , pos ,
10121066 v -> content .sequence .nelems );
10131067 break ;
1068+ case jpiObject :
1069+ read_int32 (v -> content .object .nfields , base , pos );
1070+ read_int32_n (v -> content .object .fields , base , pos ,
1071+ v -> content .object .nfields * 2 );
1072+ break ;
10141073 default :
10151074 elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
10161075 }
@@ -1078,7 +1137,8 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
10781137 v -> type == jpiKeyValue ||
10791138 v -> type == jpiStartsWith ||
10801139 v -> type == jpiSequence ||
1081- v -> type == jpiArray );
1140+ v -> type == jpiArray ||
1141+ v -> type == jpiObject );
10821142
10831143 if (a )
10841144 jspInitByBuffer (a , v -> base , v -> nextPos );
@@ -1181,3 +1241,11 @@ jspGetSequenceElement(JsonPathItem *v, int i, JsonPathItem *elem)
11811241
11821242 jspInitByBuffer (elem , v -> base , v -> content .sequence .elems [i ]);
11831243}
1244+
1245+ void
1246+ jspGetObjectField (JsonPathItem * v , int i , JsonPathItem * key , JsonPathItem * val )
1247+ {
1248+ Assert (v -> type == jpiObject );
1249+ jspInitByBuffer (key , v -> base , v -> content .object .fields [i ].key );
1250+ jspInitByBuffer (val , v -> base , v -> content .object .fields [i ].val );
1251+ }
0 commit comments