{"Entry":{"collection":"func","key":"to-jsonb","name":"to_jsonb","aliases":[],"metadata":{"changed_in":[],"changes":[{"descriptions_changed":false,"doc_overhaul":false,"from":"9.4","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"added","to":"9.5"},{"descriptions_changed":false,"doc_overhaul":true,"from":"12","group_changed":null,"signatures":{"added":[],"removed":[]},"status":"changed","to":"13"}],"content_hash":"51e14f7b4fd5f9a1bcf21c56b47bca6a476add66c2b702b5c9b7d1ade9102172","derived_content_hash":"d816719f24c349b0d608bafa4687ec8c27f053cf065eb6e923cb174aa2fc2635","documentation_refresh":{"batch":"20261113","original_source_rev":"wiki-repair-20261023:a92a2ecb85512db2b92a13458c847ca015d3dbe4eae3720037bdc207cf82a508","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"first_version":"9.5","group":"json","group_label":"Json Functions And Operators","groups":["json"],"imported_at":"2026-09-14T21:49:48.819598+08:00","last_version":"20","name":"to_jsonb","name_key":"to_jsonb","position":16060,"present_in":["9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"repair_provenance":{"original_source_revision":"2026-09-14T13:14:25.684213+00:00@99e6866c","receipt_sha256":"023d5b87bfef6ee0241e156c2d4bfdfa4aaaab5a58ba7e6b55d8fa3a342cf4ac","repair":"wiki-repair-20261023"},"signature":"to_jsonb ( anyelement ) → jsonb","signature_count":1,"slug":"to-jsonb","source_rev":"wiki-repair-20261023:a92a2ecb85512db2b92a13458c847ca015d3dbe4eae3720037bdc207cf82a508","summary":"Converts any SQL value to json or jsonb.","summary_zh":""}},"Definition":{"Collection":"func","Key":"to-jsonb","SourceDatabase":"center","Version":"18","SourceTable":"func","SourceKey":"to-jsonb","SourceRevision":"wiki-repair-20261023:a92a2ecb85512db2b92a13458c847ca015d3dbe4eae3720037bdc207cf82a508","Facts":{"description":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_html":"Converts any SQL value to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e or \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_zh":"将任何 SQL 值转换为 json 或 jsonb。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 json 的类型转换，则类型转换函数将用于执行转换；[a] 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","description_zh_html":"将任何 SQL 值转换为 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 或 \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 的类型转换，则类型转换函数将用于执行转换；\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","doc":{"anchor":"FUNCTIONS-JSON-CREATION-TABLE","file":"functions-json.html","sha256":"060b67147827d70ddcf5948833ddfbeada321366476016c8b8b7d68afda8045c","slug":"18"},"documentation_revision":{"inputs":[{"file":"functions-json.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"060b67147827d70ddcf5948833ddfbeada321366476016c8b8b7d68afda8045c","version":"18.7"},{"file":"functions-json.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"31b98fa7f00387abf441728c31918bfe8b368642bceeb8bba88a73c3fbd607de","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"},"group":"json","group_label":"JSON 函数和操作符","lang":"en","layout":"table-new","pages":["functions-json.html"],"prose_only":false,"signatures":[{"description":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_html":"Converts any SQL value to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e or \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_zh":"将任何 SQL 值转换为 json 或 jsonb。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 json 的类型转换，则类型转换函数将用于执行转换；[a] 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","description_zh_html":"将任何 SQL 值转换为 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 或 \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 的类型转换，则类型转换函数将用于执行转换；\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","examples":[{"expr":"to_json('Fred said \"Hi.\"'::text)","result":"\"Fred said \\\"Hi.\\\"\""},{"expr":"to_jsonb(row(42, 'Fred said \"Hi.\"'::text))","result":"{\"f1\": 42, \"f2\": \"Fred said \\\"Hi.\\\"\"}"}],"html":"\u003ccode class=\"function\"\u003eto_jsonb\u003c/code\u003e ( \u003ccode class=\"type\"\u003eanyelement\u003c/code\u003e ) → \u003ccode class=\"returnvalue\"\u003ejsonb\u003c/code\u003e","returns":"jsonb","text":"to_jsonb ( anyelement ) → jsonb","zh_from":"same-version-manual"}],"translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/functions-json.html","sha256":"a412feb14a229f1d9f14fa2d7735255aa297d5eb8f2971d744d9dfee659c7cca"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-manual"},"ManualEvidence":{"doc":{"anchor":"FUNCTIONS-JSON-CREATION-TABLE","file":"functions-json.html","sha256":"060b67147827d70ddcf5948833ddfbeada321366476016c8b8b7d68afda8045c","slug":"18"}},"MeasuredEvidence":{}},"Text":{"Collection":"func","Key":"to-jsonb","SourceDatabase":"center","Version":"18","Locale":"en","Title":"to_jsonb","Summary":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","BodyHTML":"Converts any SQL value to \u003ccode\u003ejson\u003c/code\u003e or \u003ccode\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\" rel=\"nofollow\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","SourceRevision":"wiki-repair-20261023:a92a2ecb85512db2b92a13458c847ca015d3dbe4eae3720037bdc207cf82a508","ContentHash":"f8e59e58d32e8de7679cac2aa1f04f9276a45edc7681ec2643a75dcaa605ebec","Payload":{"description":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_html":"Converts any SQL value to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e or \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","signatures":[{"description":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_html":"Converts any SQL value to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e or \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_zh":"将任何 SQL 值转换为 json 或 jsonb。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 json 的类型转换，则类型转换函数将用于执行转换；[a] 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","description_zh_html":"将任何 SQL 值转换为 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 或 \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 的类型转换，则类型转换函数将用于执行转换；\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","examples":[{"expr":"to_json('Fred said \"Hi.\"'::text)","result":"\"Fred said \\\"Hi.\\\"\""},{"expr":"to_jsonb(row(42, 'Fred said \"Hi.\"'::text))","result":"{\"f1\": 42, \"f2\": \"Fred said \\\"Hi.\\\"\"}"}],"html":"\u003ccode class=\"function\"\u003eto_jsonb\u003c/code\u003e ( \u003ccode class=\"type\"\u003eanyelement\u003c/code\u003e ) → \u003ccode class=\"returnvalue\"\u003ejsonb\u003c/code\u003e","returns":"jsonb","text":"to_jsonb ( anyelement ) → jsonb","zh_from":"same-version-manual"}]}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":[{"Version":"18","Ordinal":0,"Hash":"5195ea76f9b016209bec3aa170e293f984d3f7b440527af61e8c43ff10076239","Text":"to_jsonb ( anyelement ) → jsonb","Returns":"jsonb","Payload":{"description":"Converts any SQL value to json or jsonb. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to json, the cast function will be used to perform the conversion;[a] otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_html":"Converts any SQL value to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e or \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e. Arrays and composites are converted recursively to arrays and objects (multidimensional arrays become arrays of arrays in JSON). Otherwise, if there is a cast from the SQL data type to \u003ccode class=\"type\"\u003ejson\u003c/code\u003e, the cast function will be used to perform the conversion;\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e otherwise, a scalar JSON value is produced. For any scalar other than a number, a Boolean, or a null value, the text representation will be used, with escaping as necessary to make it a valid JSON string value.","description_zh":"将任何 SQL 值转换为 json 或 jsonb。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 json 的类型转换，则类型转换函数将用于执行转换；[a] 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","description_zh_html":"将任何 SQL 值转换为 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 或 \u003ccode class=\"type\"\u003ejsonb\u003c/code\u003e。数组和复合值递归地转换为数组和对象（多维数组在 JSON 中变成数组的数组）。否则，如果存在从 SQL 数据类型到 \u003ccode class=\"type\"\u003ejson\u003c/code\u003e 的类型转换，则类型转换函数将用于执行转换；\u003ca href=\"/docs/18/functions-json.html#ftn.id-1.5.8.22.8.9.2.2.1.1.3.4\"\u003e\u003csup\u003e[a]\u003c/sup\u003e\u003c/a\u003e 否则，将生成一个标量 JSON 值。对于除数字、布尔值或空值之外的任何标量，将使用文本表示，并根据需要进行转义，使其成为有效的 JSON 字符串值。","examples":[{"expr":"to_json('Fred said \"Hi.\"'::text)","result":"\"Fred said \\\"Hi.\\\"\""},{"expr":"to_jsonb(row(42, 'Fred said \"Hi.\"'::text))","result":"{\"f1\": 42, \"f2\": \"Fred said \\\"Hi.\\\"\"}"}],"html":"\u003ccode class=\"function\"\u003eto_jsonb\u003c/code\u003e ( \u003ccode class=\"type\"\u003eanyelement\u003c/code\u003e ) → \u003ccode class=\"returnvalue\"\u003ejsonb\u003c/code\u003e","returns":"jsonb","text":"to_jsonb ( anyelement ) → jsonb","zh_from":"same-version-manual"}}],"Spellings":null,"SQLState":null,"Evidence":null}
