diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 628e9de616691dbbe1c04f4607c3ae432aed5c67..0ed6a10a443b98707a16a3173c05c6cfdf19cc2a 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -1397,9 +1397,10 @@ json_categorize_type(Oid typoid,
 
 		default:
 			/* Check for arrays and composites */
-			if (OidIsValid(get_element_type(typoid)))
+			if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
+				|| typoid == RECORDARRAYOID)
 				*tcategory = JSONTYPE_ARRAY;
-			else if (type_is_rowtype(typoid))
+			else if (type_is_rowtype(typoid)) /* includes RECORDOID */
 				*tcategory = JSONTYPE_COMPOSITE;
 			else
 			{
diff --git a/src/backend/utils/adt/jsonb.c b/src/backend/utils/adt/jsonb.c
index b9bf18ffe5ddfa360b4d2fa942c1d18d6449dc3a..5b6178badf9111e63be670f6450b853b984b1abd 100644
--- a/src/backend/utils/adt/jsonb.c
+++ b/src/backend/utils/adt/jsonb.c
@@ -644,9 +644,10 @@ jsonb_categorize_type(Oid typoid,
 
 		default:
 			/* Check for arrays and composites */
-			if (OidIsValid(get_element_type(typoid)))
+			if (OidIsValid(get_element_type(typoid)) || typoid == ANYARRAYOID
+				|| typoid == RECORDARRAYOID)
 				*tcategory = JSONBTYPE_ARRAY;
-			else if (type_is_rowtype(typoid))
+			else if (type_is_rowtype(typoid)) /* includes RECORDOID */
 				*tcategory = JSONBTYPE_COMPOSITE;
 			else
 			{
diff --git a/src/test/regress/expected/json.out b/src/test/regress/expected/json.out
index efcdc4141e322294c005507ca726db91bb0022af..1bb87689fbedb199d5c79e9690eb159a9dd929eb 100644
--- a/src/test/regress/expected/json.out
+++ b/src/test/regress/expected/json.out
@@ -383,6 +383,15 @@ SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),
  {"f1":[5,6,7,8,9,10]}
 (1 row)
 
+-- anyarray column
+select to_json(histogram_bounds) histogram_bounds
+from pg_stats
+where attname = 'tmplname' and tablename = 'pg_pltemplate';
+                                   histogram_bounds                                    
+---------------------------------------------------------------------------------------
+ ["plperl","plperlu","plpgsql","plpython2u","plpython3u","plpythonu","pltcl","pltclu"]
+(1 row)
+
 -- to_json, timestamps
 select to_json(timestamp '2014-05-28 12:22:35.614298');
            to_json            
diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out
index ba9b1d711e52aadb191007c5ae9b549eba37e574..8ec4150bc285dad373b194d7539f34dd5aa2215a 100644
--- a/src/test/regress/expected/jsonb.out
+++ b/src/test/regress/expected/jsonb.out
@@ -279,6 +279,15 @@ SELECT array_to_json(ARRAY [jsonb '{"a":1}', jsonb '{"b":[2,3]}']);
  [{"a": 1},{"b": [2, 3]}]
 (1 row)
 
+-- anyarray column
+select to_jsonb(histogram_bounds) histogram_bounds
+from pg_stats
+where attname = 'tmplname' and tablename = 'pg_pltemplate';
+                                       histogram_bounds                                       
+----------------------------------------------------------------------------------------------
+ ["plperl", "plperlu", "plpgsql", "plpython2u", "plpython3u", "plpythonu", "pltcl", "pltclu"]
+(1 row)
+
 -- to_jsonb, timestamps
 select to_jsonb(timestamp '2014-05-28 12:22:35.614298');
            to_jsonb           
diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql
index 603288bd1a1ef6d67a5ad4873790dcc024c2821f..5e61922fbf11f1429795d2bdd9b34f7425e4513a 100644
--- a/src/test/regress/sql/json.sql
+++ b/src/test/regress/sql/json.sql
@@ -102,6 +102,12 @@ FROM rows q;
 
 SELECT row_to_json(row((select array_agg(x) as d from generate_series(5,10) x)),false);
 
+-- anyarray column
+
+select to_json(histogram_bounds) histogram_bounds
+from pg_stats
+where attname = 'tmplname' and tablename = 'pg_pltemplate';
+
 -- to_json, timestamps
 
 select to_json(timestamp '2014-05-28 12:22:35.614298');
diff --git a/src/test/regress/sql/jsonb.sql b/src/test/regress/sql/jsonb.sql
index eb65a3819704d5ec20df555638cabd2f731af154..e2eaca0e2722744ec197a1c9da3ecb2c508b9a7c 100644
--- a/src/test/regress/sql/jsonb.sql
+++ b/src/test/regress/sql/jsonb.sql
@@ -62,6 +62,12 @@ SELECT '    '::jsonb;			-- ERROR, no value
 -- make sure jsonb is passed through json generators without being escaped
 SELECT array_to_json(ARRAY [jsonb '{"a":1}', jsonb '{"b":[2,3]}']);
 
+-- anyarray column
+
+select to_jsonb(histogram_bounds) histogram_bounds
+from pg_stats
+where attname = 'tmplname' and tablename = 'pg_pltemplate';
+
 -- to_jsonb, timestamps
 
 select to_jsonb(timestamp '2014-05-28 12:22:35.614298');