Proposal: JSON5 support in the JSON parsers

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Proposal: JSON5 support in the JSON parsers
Date: 2026-07-14 23:10:51
Message-ID: CAN4CZFP5dvO4sij414YYG+4Hghf3M5m2oPiyR_vNgRj3vhQ_0Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

During the prototyping of configuration format proposal[1] I started
with a JSON based approach. As JSON isn't that human-friendly to
write, that prototype also needed a JSON5 compatible parser to improve
usability. I think this would be a useful improvement on its own: it
could serve as functionality available to end users in the SQL
interface and as an improved internal parser for extension authors.

JSON5 is a relaxed version of the JSON standard, a superset of the
original specification, which allows several additional syntax
features:

* Single line // and block /* comments */
* trailing commas
* unquoted object keys
* single quoted strings
* multi-line strings
* extended number formats: hexadecimal, leading/trailing decimal
point, plus sign, infinity and NaN

To make the proposal easier to review and read, I cleaned it up, added
a nicely structured test suite, and separated it into feature commits.
The first patch can be interesting by itself, as JSON with Comments
(JSONC) is a separate variant that would be a valid improvement on its
own. This structuring also makes it possible to easily skip the last
commit which adds it as a basic SQL type, or to implement that part
differently.

But the main function of the separation is to help the review process,
as some of the syntax extensions are complex, and following them in a
single patch would be difficult, especially in the incremental parser.

In addition to the tests included in the patches, I also did several
rounds of AI-assisted validations and long fuzzing runs, validating it
against other implementations. The corner cases and issues found
during these runs are now included in the test suite.

[1]: https://postgr.es/m/CAN4CZFNXdKL4eb_GwT_h-vUuUV%2BCbPCk_8-%2BS3kV8iFmNmUw7A%40mail.gmail.com

Attachment Content-Type Size
0001-Add-JSON5-comment-support-to-the-JSON-lexer.patch application/octet-stream 23.9 KB
0004-Add-JSON5-single-quoted-string-support-to-the-JSON-l.patch application/octet-stream 5.6 KB
0005-Add-JSON5-number-extensions-to-the-JSON-lexer.patch application/octet-stream 17.3 KB
0002-Add-JSON5-trailing-comma-support-to-the-JSON-parser.patch application/octet-stream 5.9 KB
0003-Add-JSON5-unquoted-object-key-support-to-the-JSON-pa.patch application/octet-stream 11.5 KB
0006-Add-JSON5-multi-line-string-support-to-the-JSON-lexe.patch application/octet-stream 5.8 KB
0008-Add-json5-type-documentation.patch application/octet-stream 4.8 KB
0007-Add-json5-data-type-with-cast-paths-to-json-jsonb.patch application/octet-stream 40.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-07-14 23:18:33 Re: Proposal: new file format for hba/ident/hosts configuration?
Previous Message Peter Geoghegan 2026-07-14 22:47:30 Hash index AM fake LSN oversight