Skip to content

Commit 9111d46

Browse files
committed
Remove ill-conceived ban on zero length json object keys.
We removed a similar ban on this in json_object recently, but the ban in datum_to_json was left, which generate4d sprutious errors in othee json generators, notable json_build_object. Along the way, add an assertion that datum_to_json is not passed a null key. All current callers comply with this rule, but the assertion will catch any possible future misbehaviour.
1 parent 5d7962c commit 9111d46

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/backend/utils/adt/json.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,9 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
13421342
bool numeric_error;
13431343
JsonLexContext dummy_lex;
13441344

1345+
/* callers are expected to ensure that null keys are not passed in */
1346+
Assert( ! (key_scalar && is_null));
1347+
13451348
if (is_null)
13461349
{
13471350
appendStringInfoString(result, "null");
@@ -1487,10 +1490,6 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
14871490
break;
14881491
default:
14891492
outputstr = OidOutputFunctionCall(outfuncoid, val);
1490-
if (key_scalar && *outputstr == '\0')
1491-
ereport(ERROR,
1492-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1493-
errmsg("key value must not be empty")));
14941493
escape_json(result, outputstr);
14951494
pfree(outputstr);
14961495
break;

0 commit comments

Comments
 (0)