@@ -479,6 +479,40 @@ flattenJsonPathParseItem(JsonPathEncodingContext *cxt, JsonPathParseItem *item,
479
479
}
480
480
}
481
481
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 ;
482
516
default :
483
517
elog (ERROR , "unrecognized jsonpath item type: %d" , item -> type );
484
518
}
@@ -795,6 +829,26 @@ printJsonPathItem(StringInfo buf, JsonPathItem *v, bool inKey,
795
829
}
796
830
appendStringInfoChar (buf , ']' );
797
831
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 ;
798
852
default :
799
853
elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
800
854
}
@@ -1011,6 +1065,11 @@ jspInitByBuffer(JsonPathItem *v, char *base, int32 pos)
1011
1065
read_int32_n (v -> content .sequence .elems , base , pos ,
1012
1066
v -> content .sequence .nelems );
1013
1067
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 ;
1014
1073
default :
1015
1074
elog (ERROR , "unrecognized jsonpath item type: %d" , v -> type );
1016
1075
}
@@ -1078,7 +1137,8 @@ jspGetNext(JsonPathItem *v, JsonPathItem *a)
1078
1137
v -> type == jpiKeyValue ||
1079
1138
v -> type == jpiStartsWith ||
1080
1139
v -> type == jpiSequence ||
1081
- v -> type == jpiArray );
1140
+ v -> type == jpiArray ||
1141
+ v -> type == jpiObject );
1082
1142
1083
1143
if (a )
1084
1144
jspInitByBuffer (a , v -> base , v -> nextPos );
@@ -1181,3 +1241,11 @@ jspGetSequenceElement(JsonPathItem *v, int i, JsonPathItem *elem)
1181
1241
1182
1242
jspInitByBuffer (elem , v -> base , v -> content .sequence .elems [i ]);
1183
1243
}
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