Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d99d0e6

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 2024ead commit d99d0e6

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
@@ -1341,6 +1341,9 @@ datum_to_json(Datum val, bool is_null, StringInfo result,
13411341
bool numeric_error;
13421342
JsonLexContext dummy_lex;
13431343

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

0 commit comments

Comments
 (0)