@@ -240,6 +240,38 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
240240 }
241241 }
242242 break ;
243+ case jpiObject :
244+ {
245+ int32 nfields = list_length (item -> value .object .fields );
246+ ListCell * lc ;
247+ int offset ;
248+
249+ appendBinaryStringInfo (buf , (char * ) & nfields , sizeof (nfields ));
250+
251+ offset = buf -> len ;
252+
253+ appendStringInfoSpaces (buf , sizeof (int32 ) * 2 * nfields );
254+
255+ foreach (lc , item -> value .object .fields )
256+ {
257+ JsonPathParseItem * field = lfirst (lc );
258+ int32 keypos =
259+ flattenJsonPathParseItem (buf , field -> value .args .left ,
260+ allowCurrent ,
261+ insideArraySubscript );
262+ int32 valpos =
263+ flattenJsonPathParseItem (buf , field -> value .args .right ,
264+ allowCurrent ,
265+ insideArraySubscript );
266+ int32 * ppos = (int32 * ) & buf -> data [offset ];
267+
268+ ppos [0 ] = keypos ;
269+ ppos [1 ] = valpos ;
270+
271+ offset += 2 * sizeof (int32 );
272+ }
273+ }
274+ break ;
243275 default :
244276 elog (ERROR , "Unknown jsonpath item type: %d" , item -> type );
245277 }
@@ -607,6 +639,26 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
607639 }
608640 appendStringInfoChar (buf , ']' );
609641 break ;
642+ case jpiObject :
643+ appendStringInfoChar (buf , '{' );
644+
645+ for (i = 0 ; i < v -> content .object .nfields ; i ++ )
646+ {
647+ JsonPathItem key ;
648+ JsonPathItem val ;
649+
650+ jspGetObjectField (v , i , & key , & val );
651+
652+ if (i )
653+ appendBinaryStringInfo (buf , ", " , 2 );
654+
655+ printJsonPathItem (buf , & key , false, false);
656+ appendBinaryStringInfo (buf , ": " , 2 );
657+ printJsonPathItem (buf , & val , false, val .type == jpiSequence );
658+ }
659+
660+ appendStringInfoChar (buf , '}' );
661+ break ;
610662 default :
611663 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
612664 }
@@ -758,6 +810,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
758810 read_int32_n (v -> content .sequence .elems , base , pos ,
759811 v -> content .sequence .nelems );
760812 break ;
813+ case jpiObject :
814+ read_int32 (v -> content .object .nfields , base , pos );
815+ read_int32_n (v -> content .object .fields , base , pos ,
816+ v -> content .object .nfields * 2 );
817+ break ;
761818 default :
762819 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
763820 }
@@ -830,7 +887,8 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
830887 v -> type == jpiStartsWith ||
831888 v -> type == jpiMap ||
832889 v -> type == jpiSequence ||
833- v -> type == jpiArray
890+ v -> type == jpiArray ||
891+ v -> type == jpiObject
834892 );
835893
836894 if (a )
@@ -940,3 +998,11 @@ jspGetSequenceElement(JsonPathItem *v, int i, JsonPathItem *elem)
940998
941999 jspInitByBuffer (elem , v -> base , v -> content .sequence .elems [i ]);
9421000}
1001+
1002+ void
1003+ jspGetObjectField (JsonPathItem * v , int i , JsonPathItem * key , JsonPathItem * val )
1004+ {
1005+ Assert (v -> type == jpiObject );
1006+ jspInitByBuffer (key , v -> base , v -> content .object .fields [i ].key );
1007+ jspInitByBuffer (val , v -> base , v -> content .object .fields [i ].val );
1008+ }
0 commit comments