@@ -217,6 +217,38 @@ flattenJsonPathParseItem(StringInfo buf, JsonPathParseItem *item,
217217 }
218218 }
219219 break ;
220+ case jpiObject :
221+ {
222+ int32 nfields = list_length (item -> value .object .fields );
223+ ListCell * lc ;
224+ int offset ;
225+
226+ appendBinaryStringInfo (buf , (char * ) & nfields , sizeof (nfields ));
227+
228+ offset = buf -> len ;
229+
230+ appendStringInfoSpaces (buf , sizeof (int32 ) * 2 * nfields );
231+
232+ foreach (lc , item -> value .object .fields )
233+ {
234+ JsonPathParseItem * field = lfirst (lc );
235+ int32 keypos =
236+ flattenJsonPathParseItem (buf , field -> value .args .left ,
237+ allowCurrent ,
238+ insideArraySubscript );
239+ int32 valpos =
240+ flattenJsonPathParseItem (buf , field -> value .args .right ,
241+ allowCurrent ,
242+ insideArraySubscript );
243+ int32 * ppos = (int32 * ) & buf -> data [offset ];
244+
245+ ppos [0 ] = keypos ;
246+ ppos [1 ] = valpos ;
247+
248+ offset += 2 * sizeof (int32 );
249+ }
250+ }
251+ break ;
220252 default :
221253 elog (ERROR , "Unknown jsonpath item type: %d" , item -> type );
222254 }
@@ -552,6 +584,26 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey, bool printBracket
552584 }
553585 appendStringInfoChar (buf , ']' );
554586 break ;
587+ case jpiObject :
588+ appendStringInfoChar (buf , '{' );
589+
590+ for (i = 0 ; i < v -> content .object .nfields ; i ++ )
591+ {
592+ JsonPathItem key ;
593+ JsonPathItem val ;
594+
595+ jspGetObjectField (v , i , & key , & val );
596+
597+ if (i )
598+ appendBinaryStringInfo (buf , ", " , 2 );
599+
600+ printJsonPathItem (buf , & key , false, false);
601+ appendBinaryStringInfo (buf , ": " , 2 );
602+ printJsonPathItem (buf , & val , false, val .type == jpiSequence );
603+ }
604+
605+ appendStringInfoChar (buf , '}' );
606+ break ;
555607 default :
556608 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
557609 }
@@ -697,6 +749,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
697749 read_int32_n (v -> content .sequence .elems , base , pos ,
698750 v -> content .sequence .nelems );
699751 break ;
752+ case jpiObject :
753+ read_int32 (v -> content .object .nfields , base , pos );
754+ read_int32_n (v -> content .object .fields , base , pos ,
755+ v -> content .object .nfields * 2 );
756+ break ;
700757 default :
701758 elog (ERROR , "Unknown jsonpath item type: %d" , v -> type );
702759 }
@@ -769,7 +826,8 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
769826 v -> type == jpiStartsWith ||
770827 v -> type == jpiMap ||
771828 v -> type == jpiSequence ||
772- v -> type == jpiArray
829+ v -> type == jpiArray ||
830+ v -> type == jpiObject
773831 );
774832
775833 if (a )
@@ -879,3 +937,11 @@ jspGetSequenceElement(JsonPathItem *v, int i, JsonPathItem *elem)
879937
880938 jspInitByBuffer (elem , v -> base , v -> content .sequence .elems [i ]);
881939}
940+
941+ void
942+ jspGetObjectField (JsonPathItem * v , int i , JsonPathItem * key , JsonPathItem * val )
943+ {
944+ Assert (v -> type == jpiObject );
945+ jspInitByBuffer (key , v -> base , v -> content .object .fields [i ].key );
946+ jspInitByBuffer (val , v -> base , v -> content .object .fields [i ].val );
947+ }
0 commit comments