@@ -529,6 +529,8 @@ static void transform_string_values_array_element_start(void *state, bool isnull
529529static void transform_string_values_scalar (void * state , char * token , JsonTokenType tokentype );
530530#endif
531531
532+ static Datum jsonb_strip_nulls_internal (Jsonb * jb );
533+
532534#ifndef JSON_C
533535/*
534536 * pg_parse_json_or_ereport
@@ -4217,7 +4219,9 @@ populate_recordset_object_field_end(void *state, char *fname, bool isnull)
42174219 hashentry -> val = _state -> saved_scalar ;
42184220 }
42194221}
4222+ #endif
42204223
4224+ #ifdef JSON_C
42214225/*
42224226 * Semantic actions for json_strip_nulls.
42234227 *
@@ -4320,12 +4324,24 @@ sn_scalar(void *state, char *token, JsonTokenType tokentype)
43204324Datum
43214325json_strip_nulls (PG_FUNCTION_ARGS )
43224326{
4323- text * json = PG_GETARG_TEXT_PP (0 );
4327+ #ifdef JSON_GENERIC
4328+ Json * json = PG_GETARG_JSONB_P (0 );
4329+ #else
4330+ text * json = PG_GETARG_TEXT_P (0 );
4331+ #endif
43244332 StripnullState * state ;
43254333 JsonLexContext * lex ;
43264334 JsonSemAction * sem ;
43274335
4336+ #ifdef JSON_GENERIC
4337+ if (json -> root .ops != & jsontContainerOps )
4338+ return jsonb_strip_nulls_internal (json );
4339+
4340+ lex = makeJsonLexContextCstringLen (json -> root .data , json -> root .len , GetDatabaseEncoding (), true);
4341+ #else
43284342 lex = makeJsonLexContext (json , true);
4343+ #endif
4344+
43294345 state = palloc0 (sizeof (StripnullState ));
43304346 sem = palloc0 (sizeof (JsonSemAction ));
43314347
@@ -4348,15 +4364,21 @@ json_strip_nulls(PG_FUNCTION_ARGS)
43484364 state -> strval -> len ));
43494365
43504366}
4351- #endif
4367+ #else
43524368
43534369/*
43544370 * SQL function jsonb_strip_nulls(jsonb) -> jsonb
43554371 */
43564372Datum
43574373jsonb_strip_nulls (PG_FUNCTION_ARGS )
43584374{
4359- Jsonb * jb = PG_GETARG_JSONB_P (0 );
4375+ return jsonb_strip_nulls_internal (PG_GETARG_JSONB_P (0 ));
4376+ }
4377+ #endif
4378+
4379+ static Datum
4380+ jsonb_strip_nulls_internal (Jsonb * jb )
4381+ {
43604382 JsonbIterator * it ;
43614383 JsonbParseState * parseState = NULL ;
43624384 JsonbValue * res = NULL ;
0 commit comments