@@ -241,6 +241,38 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
241241 }
242242 }
243243 break ;
244+ case jpiObject :
245+ {
246+ int32 nfields = list_length (item -> value .object .fields );
247+ ListCell * lc ;
248+ int offset ;
249+
250+ appendBinaryStringInfo (buf , (char * ) & nfields , sizeof (nfields ));
251+
252+ offset = buf -> len ;
253+
254+ appendStringInfoSpaces (buf , sizeof (int32 ) * 2 * nfields );
255+
256+ foreach (lc , item -> value .object .fields )
257+ {
258+ JsonPathParseItem * field = lfirst (lc );
259+ int32 keypos =
260+ flattenJsonPathParseItem (buf , field -> value .args .left ,
261+ allowCurrent ,
262+ insideArraySubscript );
263+ int32 valpos =
264+ flattenJsonPathParseItem (buf , field -> value .args .right ,
265+ allowCurrent ,
266+ insideArraySubscript );
267+ int32 * ppos = (int32 * ) & buf -> data [offset ];
268+
269+ ppos [0 ] = keypos ;
270+ ppos [1 ] = valpos ;
271+
272+ offset += 2 * sizeof (int32 );
273+ }
274+ }
275+ break ;
244276 default :
245277 elog (ERROR , "Unknown jsonpath item type: %d" , item -> type );
246278 }
@@ -614,6 +646,26 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
614646 }
615647 appendStringInfoChar (buf , ']' );
616648 break ;
649+ case jpiObject :
650+ appendStringInfoChar (buf , '{' );
651+
652+ for (i = 0 ; i < v -> content .object .nfields ; i ++ )
653+ {
654+ JsonPathItem key ;
655+ JsonPathItem val ;
656+
657+ jspGetObjectField (v , i , & key , & val );
658+
659+ if (i )
660+ appendBinaryStringInfo (buf , ", " , 2 );
661+
662+ printJsonPathItem (buf , & key , false, false);
663+ appendBinaryStringInfo (buf , ": " , 2 );
664+ printJsonPathItem (buf , & val , false, val .type == jpiSequence );
665+ }
666+
667+ appendStringInfoChar (buf , '}' );
668+ break ;
617669 default :
618670 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
619671 }
@@ -764,6 +816,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
764816 read_int32_n (v -> content .sequence .elems , base , pos ,
765817 v -> content .sequence .nelems );
766818 break ;
819+ case jpiObject :
820+ read_int32 (v -> content .object .nfields , base , pos );
821+ read_int32_n (v -> content .object .fields , base , pos ,
822+ v -> content .object .nfields * 2 );
823+ break ;
767824 default :
768825 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
769826 }
@@ -833,7 +890,8 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
833890 v -> type == jpiKeyValue ||
834891 v -> type == jpiStartsWith ||
835892 v -> type == jpiSequence ||
836- v -> type == jpiArray
893+ v -> type == jpiArray ||
894+ v -> type == jpiObject
837895 );
838896
839897 if (a )
@@ -945,3 +1003,11 @@ jspGetSequenceElement(JsonPathItem *v, int i, JsonPathItem *elem)
9451003
9461004 jspInitByBuffer (elem , v -> base , v -> content .sequence .elems [i ]);
9471005}
1006+
1007+ void
1008+ jspGetObjectField (JsonPathItem * v , int i , JsonPathItem * key , JsonPathItem * val )
1009+ {
1010+ Assert (v -> type == jpiObject );
1011+ jspInitByBuffer (key , v -> base , v -> content .object .fields [i ].key );
1012+ jspInitByBuffer (val , v -> base , v -> content .object .fields [i ].val );
1013+ }
0 commit comments