@@ -16906,6 +16906,11 @@ $ ? (@ like_regex "^\\d+$")
16906
16906
</para>
16907
16907
16908
16908
<itemizedlist>
16909
+ <listitem>
16910
+ <para>
16911
+ <xref linkend="functions-jsonparse"/>
16912
+ </para>
16913
+ </listitem>
16909
16914
<listitem>
16910
16915
<para>
16911
16916
<link linkend="functions-jsonscalar"><literal>JSON_SCALAR</literal></link>
@@ -16933,6 +16938,132 @@ $ ? (@ like_regex "^\\d+$")
16933
16938
</listitem>
16934
16939
</itemizedlist>
16935
16940
16941
+ <refentry id="functions-jsonparse">
16942
+ <refnamediv>
16943
+ <refname>JSON</refname>
16944
+ <refpurpose>create a JSON from a text</refpurpose>
16945
+ </refnamediv>
16946
+
16947
+ <refsynopsisdiv>
16948
+ <synopsis>
16949
+ JSON (
16950
+ <replaceable class="parameter">expression</replaceable> [ FORMAT JSON [ ENCODING UTF8 ] ]
16951
+ [ { WITH | WITHOUT } UNIQUE [ KEYS ] ]
16952
+ [ RETURNING <replaceable class="parameter">json_data_type</replaceable> ]
16953
+ )
16954
+ </synopsis>
16955
+ </refsynopsisdiv>
16956
+
16957
+ <refsect1>
16958
+ <title>Description</title>
16959
+
16960
+ <para>
16961
+ <function>JSON</function> function generates a <acronym>JSON</acronym>
16962
+ from a text data.
16963
+ </para>
16964
+ </refsect1>
16965
+
16966
+ <refsect1>
16967
+ <title>Parameters</title>
16968
+ <variablelist>
16969
+ <varlistentry>
16970
+ <term>
16971
+ <literal><replaceable class="parameter">expression</replaceable> [ FORMAT JSON [ ENCODING UTF8 ] ]</literal>
16972
+ </term>
16973
+ <listitem>
16974
+ <para>
16975
+ String expression that provides the <acronym>JSON</acronym> text data.
16976
+ Accepted any character strings (<type>text</type>, <type>char</type>, etc.)
16977
+ or binary strings (<type>bytea</type>) in UTF8 encoding.
16978
+ For null input, <acronym>SQL</acronym> null value is returned.
16979
+ </para>
16980
+ <para>
16981
+ The optional <literal>FORMAT</literal> clause is provided to conform
16982
+ to the SQL/JSON standard.
16983
+ </para>
16984
+ </listitem>
16985
+ </varlistentry>
16986
+ <varlistentry>
16987
+ <term>
16988
+ <literal>[ { WITH | WITHOUT } UNIQUE [ KEYS ] ]</literal>
16989
+ </term>
16990
+ <listitem>
16991
+ <para>
16992
+ Defines whether duplicate keys are allowed:
16993
+ </para>
16994
+ <variablelist>
16995
+ <varlistentry>
16996
+ <term><literal>WITHOUT</literal></term>
16997
+ <listitem>
16998
+ <para>
16999
+ Default. The constructed
17000
+ <acronym>JSON</acronym> object can contain duplicate keys.
17001
+ </para>
17002
+ </listitem>
17003
+ </varlistentry>
17004
+ <varlistentry>
17005
+ <term><literal>WITH</literal></term>
17006
+ <listitem>
17007
+ <para>
17008
+ Duplicate keys are not allowed.
17009
+ If the input data contains duplicate keys, an error is returned.
17010
+ </para>
17011
+ </listitem>
17012
+ </varlistentry>
17013
+ </variablelist>
17014
+ <para>
17015
+ Optionally, you can add the <literal>KEYS</literal> keyword for
17016
+ semantic clarity.
17017
+ </para>
17018
+ </listitem>
17019
+ </varlistentry>
17020
+ <varlistentry>
17021
+ <term>
17022
+ <literal>RETURNING <replaceable class="parameter">json_data_type</replaceable></literal>
17023
+ </term>
17024
+ <listitem>
17025
+ <para>
17026
+ The output clause that specifies the type (<type>json</type> or
17027
+ <type>jsonb</type>) of the generated <acronym>JSON</acronym>.
17028
+ </para>
17029
+ </listitem>
17030
+ </varlistentry>
17031
+ </variablelist>
17032
+ </refsect1>
17033
+
17034
+ <refsect1>
17035
+ <title>Notes</title>
17036
+ <para>
17037
+ Alternatively, you can construct <acronym>JSON</acronym> values simply
17038
+ using <productname>PostgreSQL</productname>-specific casts to
17039
+ <type>json</type> and <type>jsonb</type> types.
17040
+ </para>
17041
+ </refsect1>
17042
+ <refsect1>
17043
+ <title>Examples</title>
17044
+ <para>
17045
+ Construct a JSON the provided strings:
17046
+ </para>
17047
+ <screen>
17048
+ SELECT JSON('{ "a" : 123, "b": [ true, "foo" ], "a" : "bar" }');
17049
+ json
17050
+ --------------------------------------------------
17051
+ { "a" : 123, "b": [ true, "foo" ], "a" : "bar" }
17052
+ (1 row)
17053
+
17054
+
17055
+ SELECT JSON('{"a": 123, "b": [true, "foo"], "a": "bar"}' RETURNING jsonb);
17056
+ json
17057
+ ----------------------------------
17058
+ {"a": "bar", "b": [true, "foo"]}
17059
+ (1 row)
17060
+
17061
+ SELECT JSON('{"a": 123, "b": [true, "foo"], "a": "bar"}' WITH UNIQUE KEYS);
17062
+ ERROR: duplicate JSON object key value
17063
+ </screen>
17064
+ </refsect1>
17065
+ </refentry>
17066
+
16936
17067
<sect4 id="functions-jsonscalar">
16937
17068
<title><literal>JSON_SCALAR</literal></title>
16938
17069
<indexterm><primary>json_scalar</primary></indexterm>
0 commit comments