From c4646798125e381312baeed36dfd8f84e35331d0 Mon Sep 17 00:00:00 2001 From: Zsolt Parragi Date: Sat, 11 Jul 2026 08:16:18 +0000 Subject: [PATCH 8/8] Add json5 type documentation --- doc/src/sgml/datatype.sgml | 6 +++ doc/src/sgml/json.sgml | 87 +++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml index cc32f2e8165..ca5940b97d7 100644 --- a/doc/src/sgml/datatype.sgml +++ b/doc/src/sgml/datatype.sgml @@ -145,6 +145,12 @@ textual JSON data + + json5 + + textual JSON5 data + + jsonb diff --git a/doc/src/sgml/json.sgml b/doc/src/sgml/json.sgml index 8a2aad5935e..ad301bf4f72 100644 --- a/doc/src/sgml/json.sgml +++ b/doc/src/sgml/json.sgml @@ -26,7 +26,9 @@ data: json and jsonb. To implement efficient query mechanisms for these data types, PostgreSQL also provides the jsonpath data type described in - . + . In addition, the + json5 type described in + accepts data written in the extended JSON5 syntax. @@ -234,6 +236,89 @@ SELECT '{"reading": 1.230e-5}'::json, '{"reading": 1.230e-5}'::jsonb; + + The <type>json5</type> Type + + + JSON5 + + + + The json5 type stores data written in + JSON5, an extension of JSON + with a more permissive syntax that is intended to be easier to + write and maintain by hand. Since JSON5 is a superset of JSON, + every valid json value is also a valid + json5 value. In addition to standard JSON, the + following constructs are accepted: + + + + + Single-line (//) and block + (/* */) comments. + + + + + A single trailing comma after the last element of an array or + the last member of an object. + + + + + Unquoted object keys, for keys that are valid ECMAScript + identifiers, e.g., {key: "value"}. The words + true, false, + null, Infinity and + NaN can also be used as unquoted keys. + Identifiers are not accepted in place of values. + + + + + Single-quoted strings, e.g., 'value'. + + + + + Strings continued across multiple lines by escaping the line + break with a backslash; the escaped line break is not part of + the string value. + + + + + Extended number formats: hexadecimal integers + (0xFF), a leading or trailing decimal point + (.5, 5.), an explicit + plus sign (+5), and the special values + Infinity and NaN, + optionally preceded by a sign. + + + + + + + Like json, the json5 type stores an exact + copy of the validated input text, so comments and formatting are + preserved. There are no functions or operators that process + json5 values directly; instead, a json5 + value can be cast to json or jsonb + (both are assignment casts). These casts convert the value to + standard JSON: comments and trailing commas are removed, object + keys and strings are written in double-quoted form, and numbers + written in one of the extended formats are normalized through the + numeric type. The values Infinity, + -Infinity and NaN have no + equivalent in standard JSON, so casting a json5 value + containing them raises an error. In the other direction, + json values can be converted to json5 + implicitly, and jsonb values with an assignment cast. + + + Designing JSON Documents -- 2.43.0