diff --git a/head/schema-cplusplus/test/inputs/schema/root-array-ref.schema/default/quicktype.hpp b/head/schema-cplusplus/test/inputs/schema/root-array-ref.schema/default/quicktype.hpp
new file mode 100644
index 0000000..74cdcc1
--- /dev/null
+++ b/head/schema-cplusplus/test/inputs/schema/root-array-ref.schema/default/quicktype.hpp
@@ -0,0 +1,63 @@
+//  To parse this JSON data, first install
+//
+//      json.hpp  https://github.com/nlohmann/json
+//
+//  Then include this file, and then do
+//
+//     TopLevel data = nlohmann::json::parse(jsonString);
+
+#pragma once
+
+#include "json.hpp"
+
+#include <optional>
+#include <stdexcept>
+#include <regex>
+
+namespace quicktype {
+    using nlohmann::json;
+
+    #ifndef NLOHMANN_UNTYPED_quicktype_HELPER
+    #define NLOHMANN_UNTYPED_quicktype_HELPER
+    inline json get_untyped(const json & j, const char * property) {
+        if (j.find(property) != j.end()) {
+            return j.at(property).get<json>();
+        }
+        return json();
+    }
+
+    inline json get_untyped(const json & j, std::string property) {
+        return get_untyped(j, property.data());
+    }
+    #endif
+
+    class SomeObject {
+        public:
+        SomeObject() = default;
+        virtual ~SomeObject() = default;
+
+        private:
+        std::string name;
+
+        public:
+        const std::string & get_name() const { return name; }
+        std::string & get_mutable_name() { return name; }
+        void set_name(const std::string & value) { this->name = value; }
+    };
+
+    using TopLevel = std::vector<SomeObject>;
+}
+
+namespace quicktype {
+    void from_json(const json & j, SomeObject & x);
+    void to_json(json & j, const SomeObject & x);
+
+    inline void from_json(const json & j, SomeObject& x) {
+        x.set_name(j.at("name").get<std::string>());
+    }
+
+    inline void to_json(json & j, const SomeObject & x) {
+        j = json::object();
+        j["name"] = x.get_name();
+    }
+}
diff --git a/head/schema-csharp/test/inputs/schema/root-array-ref.schema/default/QuickType.cs b/head/schema-csharp/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
new file mode 100644
index 0000000..703993c
--- /dev/null
+++ b/head/schema-csharp/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
@@ -0,0 +1,61 @@
+// <auto-generated />
+//
+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
+//
+//    using QuickType;
+//
+//    var topLevel = TopLevel.FromJson(jsonString);
+#nullable enable
+#pragma warning disable CS8618
+#pragma warning disable CS8601
+#pragma warning disable CS8602
+#pragma warning disable CS8603
+#pragma warning disable CS8604
+#pragma warning disable CS8625
+#pragma warning disable CS8765
+
+namespace QuickType
+{
+    using System;
+    using System.Collections.Generic;
+
+    using System.Globalization;
+    using Newtonsoft.Json;
+    using Newtonsoft.Json.Converters;
+
+    public partial class TopLevel
+    {
+        [JsonProperty("name", Required = Required.Always)]
+        public string Name { get; set; }
+    }
+
+    public partial class TopLevel
+    {
+        public static TopLevel[] FromJson(string json) => JsonConvert.DeserializeObject<TopLevel[]>(json, QuickType.Converter.Settings);
+    }
+
+    public static partial class Serialize
+    {
+        public static string ToJson(this TopLevel[] self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
+    }
+
+    internal static partial class Converter
+    {
+        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
+        {
+            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
+            DateParseHandling = DateParseHandling.None,
+            Converters =
+            {
+                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
+            },
+        };
+    }
+}
+#pragma warning restore CS8618
+#pragma warning restore CS8601
+#pragma warning restore CS8602
+#pragma warning restore CS8603
+#pragma warning restore CS8604
+#pragma warning restore CS8625
+#pragma warning restore CS8765
diff --git a/head/schema-csharp-SystemTextJson/test/inputs/schema/root-array-ref.schema/default/QuickType.cs b/head/schema-csharp-SystemTextJson/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
new file mode 100644
index 0000000..058a0cf
--- /dev/null
+++ b/head/schema-csharp-SystemTextJson/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
@@ -0,0 +1,166 @@
+// <auto-generated />
+//
+// To parse this JSON data, add NuGet 'System.Text.Json' then do:
+//
+//    using QuickType;
+//
+//    var topLevel = TopLevel.FromJson(jsonString);
+#nullable enable
+#pragma warning disable CS8618
+#pragma warning disable CS8601
+#pragma warning disable CS8602
+#pragma warning disable CS8603
+
+namespace QuickType
+{
+    using System;
+    using System.Collections.Generic;
+
+    using System.Text.Json;
+    using System.Text.Json.Serialization;
+    using System.Globalization;
+
+    public partial class TopLevel
+    {
+        [JsonRequired]
+        [JsonPropertyName("name")]
+        public string Name { get; set; }
+    }
+
+    public partial class TopLevel
+    {
+        public static TopLevel[] FromJson(string json) => JsonSerializer.Deserialize<TopLevel[]>(json, QuickType.Converter.Settings);
+    }
+
+    public static partial class Serialize
+    {
+        public static string ToJson(this TopLevel[] self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings);
+    }
+
+    internal static partial class Converter
+    {
+        public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
+        {
+            Converters =
+            {
+                new DateOnlyConverter(),
+                new TimeOnlyConverter(),
+                IsoDateTimeOffsetConverter.Singleton
+            },
+        };
+    }
+    
+    public class DateOnlyConverter : JsonConverter<DateOnly>
+    {
+        private readonly string serializationFormat;
+        public DateOnlyConverter() : this(null) { }
+
+        public DateOnlyConverter(string? serializationFormat)
+        {
+                this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
+        }
+
+        public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        {
+                var value = reader.GetString();
+                return DateOnly.Parse(value!);
+        }
+
+        public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
+                => writer.WriteStringValue(value.ToString(serializationFormat));
+    }
+
+    public class TimeOnlyConverter : JsonConverter<TimeOnly>
+    {
+        private readonly string serializationFormat;
+
+        public TimeOnlyConverter() : this(null) { }
+
+        public TimeOnlyConverter(string? serializationFormat)
+        {
+                this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
+        }
+
+        public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        {
+                var value = reader.GetString();
+                return TimeOnly.Parse(value!);
+        }
+
+        public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
+                => writer.WriteStringValue(value.ToString(serializationFormat));
+    }
+
+    internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
+    {
+        public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
+
+        private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
+
+        private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
+        private string? _dateTimeFormat;
+        private CultureInfo? _culture;
+
+        public DateTimeStyles DateTimeStyles
+        {
+                get => _dateTimeStyles;
+                set => _dateTimeStyles = value;
+        }
+
+        public string? DateTimeFormat
+        {
+                get => _dateTimeFormat ?? string.Empty;
+                set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
+        }
+
+        public CultureInfo Culture
+        {
+                get => _culture ?? CultureInfo.CurrentCulture;
+                set => _culture = value;
+        }
+
+        public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
+        {
+                string text;
+
+
+                if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
+                        || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
+                {
+                        value = value.ToUniversalTime();
+                }
+
+                text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
+
+                writer.WriteStringValue(text);
+        }
+
+        public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+        {
+                string? dateText = reader.GetString();
+
+                if (string.IsNullOrEmpty(dateText) == false)
+                {
+                        if (!string.IsNullOrEmpty(_dateTimeFormat))
+                        {
+                                return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
+                        }
+                        else
+                        {
+                                return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
+                        }
+                }
+                else
+                {
+                        return default(DateTimeOffset);
+                }
+        }
+
+
+        public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
+    }
+}
+#pragma warning restore CS8618
+#pragma warning restore CS8601
+#pragma warning restore CS8602
+#pragma warning restore CS8603
diff --git a/head/schema-csharp-records/test/inputs/schema/root-array-ref.schema/default/QuickType.cs b/head/schema-csharp-records/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
new file mode 100644
index 0000000..04ddf33
--- /dev/null
+++ b/head/schema-csharp-records/test/inputs/schema/root-array-ref.schema/default/QuickType.cs
@@ -0,0 +1,61 @@
+// <auto-generated />
+//
+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
+//
+//    using QuickType;
+//
+//    var topLevel = TopLevel.FromJson(jsonString);
+#nullable enable
+#pragma warning disable CS8618
+#pragma warning disable CS8601
+#pragma warning disable CS8602
+#pragma warning disable CS8603
+#pragma warning disable CS8604
+#pragma warning disable CS8625
+#pragma warning disable CS8765
+
+namespace QuickType
+{
+    using System;
+    using System.Collections.Generic;
+
+    using System.Globalization;
+    using Newtonsoft.Json;
+    using Newtonsoft.Json.Converters;
+
+    public partial record TopLevel
+    {
+        [JsonProperty("name", Required = Required.Always)]
+        public string Name { get; set; }
+    }
+
+    public partial record TopLevel
+    {
+        public static TopLevel[] FromJson(string json) => JsonConvert.DeserializeObject<TopLevel[]>(json, QuickType.Converter.Settings);
+    }
+
+    public static partial class Serialize
+    {
+        public static string ToJson(this TopLevel[] self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
+    }
+
+    internal static partial class Converter
+    {
+        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
+        {
+            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
+            DateParseHandling = DateParseHandling.None,
+            Converters =
+            {
+                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
+            },
+        };
+    }
+}
+#pragma warning restore CS8618
+#pragma warning restore CS8601
+#pragma warning restore CS8602
+#pragma warning restore CS8603
+#pragma warning restore CS8604
+#pragma warning restore CS8625
+#pragma warning restore CS8765
diff --git a/head/schema-dart/test/inputs/schema/root-array-ref.schema/default/TopLevel.dart b/head/schema-dart/test/inputs/schema/root-array-ref.schema/default/TopLevel.dart
new file mode 100644
index 0000000..b853fb2
--- /dev/null
+++ b/head/schema-dart/test/inputs/schema/root-array-ref.schema/default/TopLevel.dart
@@ -0,0 +1,25 @@
+// To parse this JSON data, do
+//
+//     final topLevel = topLevelFromJson(jsonString);
+
+import 'dart:convert';
+
+List<TopLevel> topLevelFromJson(String str) => List<TopLevel>.from(json.decode(str).map((x) => TopLevel.fromJson(x)));
+
+String topLevelToJson(List<TopLevel> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
+
+class TopLevel {
+    final String name;
+
+    TopLevel({
+        required this.name,
+    });
+
+    factory TopLevel.fromJson(Map<String, dynamic> json) => TopLevel(
+        name: json["name"],
+    );
+
+    Map<String, dynamic> toJson() => {
+        "name": name,
+    };
+}
diff --git a/head/schema-elm/test/inputs/schema/root-array-ref.schema/default/QuickType.elm b/head/schema-elm/test/inputs/schema/root-array-ref.schema/default/QuickType.elm
new file mode 100644
index 0000000..1f32c3f
--- /dev/null
+++ b/head/schema-elm/test/inputs/schema/root-array-ref.schema/default/QuickType.elm
@@ -0,0 +1,57 @@
+-- To decode the JSON data, add this file to your project, run
+--
+--     elm install NoRedInk/elm-json-decode-pipeline
+--
+-- add these imports
+--
+--     import Json.Decode exposing (decodeString)
+--     import QuickType exposing (quickType)
+--
+-- and you're off to the races with
+--
+--     decodeString quickType myJsonString
+
+module QuickType exposing
+    ( QuickType
+    , quickTypeToString
+    , quickType
+    , SomeObject
+    )
+
+import Json.Decode as Jdec
+import Json.Decode.Pipeline as Jpipe
+import Json.Encode as Jenc
+import Dict exposing (Dict)
+
+type alias QuickType = List SomeObject
+
+type alias SomeObject =
+    { name : String
+    }
+
+-- decoders and encoders
+
+quickType : Jdec.Decoder QuickType
+quickType = Jdec.list someObject
+
+quickTypeToString : QuickType -> String
+quickTypeToString r = Jenc.encode 0 (Jenc.list encodeSomeObject r)
+
+someObject : Jdec.Decoder SomeObject
+someObject =
+    Jdec.succeed SomeObject
+        |> Jpipe.required "name" Jdec.string
+
+encodeSomeObject : SomeObject -> Jenc.Value
+encodeSomeObject x =
+    Jenc.object
+        [ ("name", Jenc.string x.name)
+        ]
+
+--- encoder helpers
+
+makeNullableEncoder : (a -> Jenc.Value) -> Maybe a -> Jenc.Value
+makeNullableEncoder f m =
+    case m of
+    Just x -> f x
+    Nothing -> Jenc.null
diff --git a/head/schema-flow/test/inputs/schema/root-array-ref.schema/default/TopLevel.js b/head/schema-flow/test/inputs/schema/root-array-ref.schema/default/TopLevel.js
new file mode 100644
index 0000000..92007ab
--- /dev/null
+++ b/head/schema-flow/test/inputs/schema/root-array-ref.schema/default/TopLevel.js
@@ -0,0 +1,188 @@
+// @flow
+
+// To parse this data:
+//
+//   const Convert = require("./TopLevel");
+//
+//   const topLevel = Convert.toTopLevel(json);
+//
+// These functions will throw an error if the JSON doesn't
+// match the expected interface, even if the JSON is valid.
+
+export type TopLevel = {
+    name: string;
+};
+
+// Converts JSON strings to/from your types
+// and asserts the results of JSON.parse at runtime
+function toTopLevel(json: string): TopLevel[] {
+    return cast(JSON.parse(json), a(r("TopLevel")));
+}
+
+function topLevelToJson(value: TopLevel[]): string {
+    return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+}
+
+function invalidValue(typ: any, val: any, key: any, parent: any = '') {
+    const prettyTyp = prettyTypeName(typ);
+    const parentText = parent ? ` on ${parent}` : '';
+    const keyText = key ? ` for key "${key}"` : '';
+    throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
+}
+
+function prettyTypeName(typ: any): string {
+    if (Array.isArray(typ)) {
+        if (typ.length === 2 && typ[0] === undefined) {
+            return `an optional ${prettyTypeName(typ[1])}`;
+        } else {
+            return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
+        }
+    } else if (typeof typ === "object" && typ.literal !== undefined) {
+        return typ.literal;
+    } else {
+        return typeof typ;
+    }
+}
+
+function jsonToJSProps(typ: any): any {
+    if (typ.jsonToJS === undefined) {
+        const map: any = {};
+        typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
+        typ.jsonToJS = map;
+    }
+    return typ.jsonToJS;
+}
+
+function jsToJSONProps(typ: any): any {
+    if (typ.jsToJSON === undefined) {
+        const map: any = {};
+        typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
+        typ.jsToJSON = map;
+    }
+    return typ.jsToJSON;
+}
+
+function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
+    function transformPrimitive(typ: string, val: any): any {
+        if (typeof typ === typeof val) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+
+    function transformUnion(typs: any[], val: any): any {
+        // val must validate against one typ in typs
+        const l = typs.length;
+        for (let i = 0; i < l; i++) {
+            const typ = typs[i];
+            try {
+                return transform(val, typ, getProps);
+            } catch (_) {}
+        }
+        return invalidValue(typs, val, key, parent);
+    }
+
+    function transformEnum(cases: string[], val: any): any {
+        if (cases.indexOf(val) !== -1) return val;
+        return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
+    }
+
+    function transformArray(typ: any, val: any): any {
+        // val must be an array with no invalid elements
+        if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
+        return val.map(el => transform(el, typ, getProps));
+    }
+
+    function transformDate(val: any): any {
+        if (val === null) {
+            return null;
+        }
+        const d = new Date(val);
+        if (isNaN(d.valueOf())) {
+            return invalidValue(l("Date"), val, key, parent);
+        }
+        return d;
+    }
+
+    function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
+        if (val === null || typeof val !== "object" || Array.isArray(val)) {
+            return invalidValue(l(ref || "object"), val, key, parent);
+        }
+        const result: any = {};
+        Object.getOwnPropertyNames(props).forEach(key => {
+            const prop = props[key];
+            const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
+            result[prop.key] = transform(v, prop.typ, getProps, key, ref);
+        });
+        Object.getOwnPropertyNames(val).forEach(key => {
+            if (!Object.prototype.hasOwnProperty.call(props, key)) {
+                result[key] = transform(val[key], additional, getProps, key, ref);
+            }
+        });
+        return result;
+    }
+
+    if (typ === "any") return val;
+    if (typ === null) {
+        if (val === null) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+    if (typ === false) return invalidValue(typ, val, key, parent);
+    let ref: any = undefined;
+    while (typeof typ === "object" && typ.ref !== undefined) {
+        ref = typ.ref;
+        typ = typeMap[typ.ref];
+    }
+    if (Array.isArray(typ)) return transformEnum(typ, val);
+    if (typeof typ === "object") {
+        return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
+            : typ.hasOwnProperty("arrayItems")    ? transformArray(typ.arrayItems, val)
+            : typ.hasOwnProperty("props")         ? transformObject(getProps(typ), typ.additional, val)
+            : invalidValue(typ, val, key, parent);
+    }
+    // Numbers can be parsed by Date but shouldn't be.
+    if (typ === Date && typeof val !== "number") return transformDate(val);
+    return transformPrimitive(typ, val);
+}
+
+function cast<T>(val: any, typ: any): T {
+    return transform(val, typ, jsonToJSProps);
+}
+
+function uncast<T>(val: T, typ: any): any {
+    return transform(val, typ, jsToJSONProps);
+}
+
+function l(typ: any) {
+    return { literal: typ };
+}
+
+function a(typ: any) {
+    return { arrayItems: typ };
+}
+
+function u(...typs: any[]) {
+    return { unionMembers: typs };
+}
+
+function o(props: any[], additional: any) {
+    return { props, additional };
+}
+
+function m(additional: any) {
+    const props: any[] = [];
+    return { props, additional };
+}
+
+function r(name: string) {
+    return { ref: name };
+}
+
+const typeMap: any = {
+    "TopLevel": o([
+        { json: "name", js: "name", typ: "" },
+    ], false),
+};
+
+module.exports = {
+    "topLevelToJson": topLevelToJson,
+    "toTopLevel": toTopLevel,
+};
diff --git a/head/schema-golang/test/inputs/schema/root-array-ref.schema/default/quicktype.go b/head/schema-golang/test/inputs/schema/root-array-ref.schema/default/quicktype.go
new file mode 100644
index 0000000..c3eba1b
--- /dev/null
+++ b/head/schema-golang/test/inputs/schema/root-array-ref.schema/default/quicktype.go
@@ -0,0 +1,25 @@
+// Code generated from JSON Schema using quicktype. DO NOT EDIT.
+// To parse and unparse this JSON data, add this code to your project and do:
+//
+//    topLevel, err := UnmarshalTopLevel(bytes)
+//    bytes, err = topLevel.Marshal()
+
+package main
+
+import "encoding/json"
+
+type TopLevel []SomeObject
+
+func UnmarshalTopLevel(data []byte) (TopLevel, error) {
+	var r TopLevel
+	err := json.Unmarshal(data, &r)
+	return r, err
+}
+
+func (r *TopLevel) Marshal() ([]byte, error) {
+	return json.Marshal(r)
+}
+
+type SomeObject struct {
+	Name string `json:"name"`
+}
diff --git a/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java b/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
new file mode 100644
index 0000000..6af78ce
--- /dev/null
+++ b/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
@@ -0,0 +1,101 @@
+// To use this code, add the following Maven dependency to your project:
+//
+//
+//     com.fasterxml.jackson.core     : jackson-databind          : 2.9.0
+//     com.fasterxml.jackson.datatype : jackson-datatype-jsr310   : 2.9.0
+//
+// Import this package:
+//
+//     import io.quicktype.Converter;
+//
+// Then you can deserialize a JSON string with
+//
+//     List<TopLevel> data = Converter.fromJsonString(jsonString);
+
+package io.quicktype;
+
+import java.io.IOException;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.util.*;
+import java.time.LocalDate;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.temporal.ChronoField;
+
+public class Converter {
+    // Date-time helpers
+
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
+            .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
+            .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
+            .appendOptional(DateTimeFormatter.ISO_INSTANT)
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+            .toFormatter()
+            .withZone(ZoneOffset.UTC);
+
+    public static OffsetDateTime parseDateTimeString(String str) {
+        return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();
+    }
+
+    private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()
+            .appendOptional(DateTimeFormatter.ISO_TIME)
+            .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)
+            .parseDefaulting(ChronoField.YEAR, 2020)
+            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
+            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
+            .toFormatter()
+            .withZone(ZoneOffset.UTC);
+
+    public static OffsetTime parseTimeString(String str) {
+        return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();
+    }
+    // Serialize/deserialize helpers
+
+    public static List<TopLevel> fromJsonString(String json) throws IOException {
+        return getObjectReader().readValue(json);
+    }
+
+    public static String toJsonString(List<TopLevel> obj) throws JsonProcessingException {
+        return getObjectWriter().writeValueAsString(obj);
+    }
+
+    private static ObjectReader reader;
+    private static ObjectWriter writer;
+
+    private static void instantiateMapper() {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.findAndRegisterModules();
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() {
+            @Override
+            public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+                String value = jsonParser.getText();
+                return Converter.parseDateTimeString(value);
+            }
+        });
+        mapper.registerModule(module);
+        reader = mapper.readerFor(List.class);
+        writer = mapper.writerFor(List.class);
+    }
+
+    private static ObjectReader getObjectReader() {
+        if (reader == null) instantiateMapper();
+        return reader;
+    }
+
+    private static ObjectWriter getObjectWriter() {
+        if (writer == null) instantiateMapper();
+        return writer;
+    }
+}
diff --git a/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java b/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
new file mode 100644
index 0000000..343dd75
--- /dev/null
+++ b/head/schema-java/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
@@ -0,0 +1,12 @@
+package io.quicktype;
+
+import com.fasterxml.jackson.annotation.*;
+
+public class TopLevel {
+    private String name;
+
+    @JsonProperty("name")
+    public String getName() { return name; }
+    @JsonProperty("name")
+    public void setName(String value) { this.name = value; }
+}
diff --git a/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java b/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
new file mode 100644
index 0000000..b71b390
--- /dev/null
+++ b/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
@@ -0,0 +1,121 @@
+// To use this code, add the following Maven dependency to your project:
+//
+//
+//     com.fasterxml.jackson.core     : jackson-databind          : 2.9.0
+//
+//
+// Import this package:
+//
+//     import io.quicktype.Converter;
+//
+// Then you can deserialize a JSON string with
+//
+//     List<TopLevel> data = Converter.fromJsonString(jsonString);
+
+package io.quicktype;
+
+import java.io.IOException;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.util.*;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
+public class Converter {
+    // Date-time helpers
+
+    private static final String[] DATE_TIME_FORMATS = {
+            "yyyy-MM-dd'T'HH:mm:ss.SX",
+            "yyyy-MM-dd'T'HH:mm:ss.S",
+            "yyyy-MM-dd'T'HH:mm:ssX",
+            "yyyy-MM-dd'T'HH:mm:ss",
+            "yyyy-MM-dd HH:mm:ss.SX",
+            "yyyy-MM-dd HH:mm:ss.S",
+            "yyyy-MM-dd HH:mm:ssX",
+            "yyyy-MM-dd HH:mm:ss",
+            "HH:mm:ss.SZ",
+            "HH:mm:ss.S",
+            "HH:mm:ssZ",
+            "HH:mm:ss",
+            "yyyy-MM-dd",
+    };
+
+    public static Date parseAllDateTimeString(String str) {
+        for (String format : DATE_TIME_FORMATS) {
+            try {
+                return new SimpleDateFormat(format).parse(str);
+            } catch (Exception ex) {
+                // Ignored
+            }
+        }
+        return null;
+    }
+
+    public static String serializeDateTime(Date datetime) {
+        return new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ").format(datetime);
+    }
+
+    public static String serializeDate(Date datetime) {
+        return new SimpleDateFormat("yyyy-MM-dd").format(datetime);
+    }
+
+    public static String serializeTime(Date datetime) {
+        return new SimpleDateFormat("hh:mm:ssZ").format(datetime);
+    }
+    // Serialize/deserialize helpers
+
+    public static List<TopLevel> fromJsonString(String json) throws IOException {
+        return getObjectReader().readValue(json);
+    }
+
+    public static String toJsonString(List<TopLevel> obj) throws JsonProcessingException {
+        return getObjectWriter().writeValueAsString(obj);
+    }
+
+    private static ObjectReader reader;
+    private static ObjectWriter writer;
+
+    private static void instantiateMapper() {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.findAndRegisterModules();
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
+            @Override
+            public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+                String value = jsonParser.getText();
+                return Converter.parseAllDateTimeString(value);
+            }
+        });
+        module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
+            @Override
+            public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+                String value = jsonParser.getText();
+                return Converter.parseAllDateTimeString(value);
+            }
+        });
+        module.addDeserializer(Date.class, new JsonDeserializer<Date>() {
+            @Override
+            public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+                String value = jsonParser.getText();
+                return Converter.parseAllDateTimeString(value);
+            }
+        });
+        mapper.registerModule(module);
+        reader = mapper.readerFor(List.class);
+        writer = mapper.writerFor(List.class);
+    }
+
+    private static ObjectReader getObjectReader() {
+        if (reader == null) instantiateMapper();
+        return reader;
+    }
+
+    private static ObjectWriter getObjectWriter() {
+        if (writer == null) instantiateMapper();
+        return writer;
+    }
+}
diff --git a/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java b/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
new file mode 100644
index 0000000..343dd75
--- /dev/null
+++ b/head/schema-java-datetime-legacy/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
@@ -0,0 +1,12 @@
+package io.quicktype;
+
+import com.fasterxml.jackson.annotation.*;
+
+public class TopLevel {
+    private String name;
+
+    @JsonProperty("name")
+    public String getName() { return name; }
+    @JsonProperty("name")
+    public void setName(String value) { this.name = value; }
+}
diff --git a/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java b/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
new file mode 100644
index 0000000..6af78ce
--- /dev/null
+++ b/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/Converter.java
@@ -0,0 +1,101 @@
+// To use this code, add the following Maven dependency to your project:
+//
+//
+//     com.fasterxml.jackson.core     : jackson-databind          : 2.9.0
+//     com.fasterxml.jackson.datatype : jackson-datatype-jsr310   : 2.9.0
+//
+// Import this package:
+//
+//     import io.quicktype.Converter;
+//
+// Then you can deserialize a JSON string with
+//
+//     List<TopLevel> data = Converter.fromJsonString(jsonString);
+
+package io.quicktype;
+
+import java.io.IOException;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.util.*;
+import java.time.LocalDate;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.temporal.ChronoField;
+
+public class Converter {
+    // Date-time helpers
+
+    private static final DateTimeFormatter DATE_TIME_FORMATTER = new DateTimeFormatterBuilder()
+            .appendOptional(DateTimeFormatter.ISO_DATE_TIME)
+            .appendOptional(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
+            .appendOptional(DateTimeFormatter.ISO_INSTANT)
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SX"))
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssX"))
+            .appendOptional(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
+            .toFormatter()
+            .withZone(ZoneOffset.UTC);
+
+    public static OffsetDateTime parseDateTimeString(String str) {
+        return ZonedDateTime.from(Converter.DATE_TIME_FORMATTER.parse(str)).toOffsetDateTime();
+    }
+
+    private static final DateTimeFormatter TIME_FORMATTER = new DateTimeFormatterBuilder()
+            .appendOptional(DateTimeFormatter.ISO_TIME)
+            .appendOptional(DateTimeFormatter.ISO_OFFSET_TIME)
+            .parseDefaulting(ChronoField.YEAR, 2020)
+            .parseDefaulting(ChronoField.MONTH_OF_YEAR, 1)
+            .parseDefaulting(ChronoField.DAY_OF_MONTH, 1)
+            .toFormatter()
+            .withZone(ZoneOffset.UTC);
+
+    public static OffsetTime parseTimeString(String str) {
+        return ZonedDateTime.from(Converter.TIME_FORMATTER.parse(str)).toOffsetDateTime().toOffsetTime();
+    }
+    // Serialize/deserialize helpers
+
+    public static List<TopLevel> fromJsonString(String json) throws IOException {
+        return getObjectReader().readValue(json);
+    }
+
+    public static String toJsonString(List<TopLevel> obj) throws JsonProcessingException {
+        return getObjectWriter().writeValueAsString(obj);
+    }
+
+    private static ObjectReader reader;
+    private static ObjectWriter writer;
+
+    private static void instantiateMapper() {
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.findAndRegisterModules();
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+        SimpleModule module = new SimpleModule();
+        module.addDeserializer(OffsetDateTime.class, new JsonDeserializer<OffsetDateTime>() {
+            @Override
+            public OffsetDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
+                String value = jsonParser.getText();
+                return Converter.parseDateTimeString(value);
+            }
+        });
+        mapper.registerModule(module);
+        reader = mapper.readerFor(List.class);
+        writer = mapper.writerFor(List.class);
+    }
+
+    private static ObjectReader getObjectReader() {
+        if (reader == null) instantiateMapper();
+        return reader;
+    }
+
+    private static ObjectWriter getObjectWriter() {
+        if (writer == null) instantiateMapper();
+        return writer;
+    }
+}
diff --git a/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java b/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
new file mode 100644
index 0000000..343dd75
--- /dev/null
+++ b/head/schema-java-lombok/test/inputs/schema/root-array-ref.schema/default/src/main/java/io/quicktype/TopLevel.java
@@ -0,0 +1,12 @@
+package io.quicktype;
+
+import com.fasterxml.jackson.annotation.*;
+
+public class TopLevel {
+    private String name;
+
+    @JsonProperty("name")
+    public String getName() { return name; }
+    @JsonProperty("name")
+    public void setName(String value) { this.name = value; }
+}
diff --git a/head/schema-javascript/test/inputs/schema/root-array-ref.schema/default/TopLevel.js b/head/schema-javascript/test/inputs/schema/root-array-ref.schema/default/TopLevel.js
new file mode 100644
index 0000000..5ca732f
--- /dev/null
+++ b/head/schema-javascript/test/inputs/schema/root-array-ref.schema/default/TopLevel.js
@@ -0,0 +1,182 @@
+// To parse this data:
+//
+//   const Convert = require("./TopLevel");
+//
+//   const topLevel = Convert.toTopLevel(json);
+//
+// These functions will throw an error if the JSON doesn't
+// match the expected interface, even if the JSON is valid.
+
+// Converts JSON strings to/from your types
+// and asserts the results of JSON.parse at runtime
+function toTopLevel(json) {
+    return cast(JSON.parse(json), a(r("TopLevel")));
+}
+
+function topLevelToJson(value) {
+    return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+}
+
+function invalidValue(typ, val, key, parent = '') {
+    const prettyTyp = prettyTypeName(typ);
+    const parentText = parent ? ` on ${parent}` : '';
+    const keyText = key ? ` for key "${key}"` : '';
+    throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
+}
+
+function prettyTypeName(typ) {
+    if (Array.isArray(typ)) {
+        if (typ.length === 2 && typ[0] === undefined) {
+            return `an optional ${prettyTypeName(typ[1])}`;
+        } else {
+            return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
+        }
+    } else if (typeof typ === "object" && typ.literal !== undefined) {
+        return typ.literal;
+    } else {
+        return typeof typ;
+    }
+}
+
+function jsonToJSProps(typ) {
+    if (typ.jsonToJS === undefined) {
+        const map = {};
+        typ.props.forEach((p) => map[p.json] = { key: p.js, typ: p.typ });
+        typ.jsonToJS = map;
+    }
+    return typ.jsonToJS;
+}
+
+function jsToJSONProps(typ) {
+    if (typ.jsToJSON === undefined) {
+        const map = {};
+        typ.props.forEach((p) => map[p.js] = { key: p.json, typ: p.typ });
+        typ.jsToJSON = map;
+    }
+    return typ.jsToJSON;
+}
+
+function transform(val, typ, getProps, key = '', parent = '') {
+    function transformPrimitive(typ, val) {
+        if (typeof typ === typeof val) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+
+    function transformUnion(typs, val) {
+        // val must validate against one typ in typs
+        const l = typs.length;
+        for (let i = 0; i < l; i++) {
+            const typ = typs[i];
+            try {
+                return transform(val, typ, getProps);
+            } catch (_) {}
+        }
+        return invalidValue(typs, val, key, parent);
+    }
+
+    function transformEnum(cases, val) {
+        if (cases.indexOf(val) !== -1) return val;
+        return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
+    }
+
+    function transformArray(typ, val) {
+        // val must be an array with no invalid elements
+        if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
+        return val.map(el => transform(el, typ, getProps));
+    }
+
+    function transformDate(val) {
+        if (val === null) {
+            return null;
+        }
+        const d = new Date(val);
+        if (isNaN(d.valueOf())) {
+            return invalidValue(l("Date"), val, key, parent);
+        }
+        return d;
+    }
+
+    function transformObject(props, additional, val) {
+        if (val === null || typeof val !== "object" || Array.isArray(val)) {
+            return invalidValue(l(ref || "object"), val, key, parent);
+        }
+        const result = {};
+        Object.getOwnPropertyNames(props).forEach(key => {
+            const prop = props[key];
+            const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
+            result[prop.key] = transform(v, prop.typ, getProps, key, ref);
+        });
+        Object.getOwnPropertyNames(val).forEach(key => {
+            if (!Object.prototype.hasOwnProperty.call(props, key)) {
+                result[key] = transform(val[key], additional, getProps, key, ref);
+            }
+        });
+        return result;
+    }
+
+    if (typ === "any") return val;
+    if (typ === null) {
+        if (val === null) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+    if (typ === false) return invalidValue(typ, val, key, parent);
+    let ref = undefined;
+    while (typeof typ === "object" && typ.ref !== undefined) {
+        ref = typ.ref;
+        typ = typeMap[typ.ref];
+    }
+    if (Array.isArray(typ)) return transformEnum(typ, val);
+    if (typeof typ === "object") {
+        return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
+            : typ.hasOwnProperty("arrayItems")    ? transformArray(typ.arrayItems, val)
+            : typ.hasOwnProperty("props")         ? transformObject(getProps(typ), typ.additional, val)
+            : invalidValue(typ, val, key, parent);
+    }
+    // Numbers can be parsed by Date but shouldn't be.
+    if (typ === Date && typeof val !== "number") return transformDate(val);
+    return transformPrimitive(typ, val);
+}
+
+function cast(val, typ) {
+    return transform(val, typ, jsonToJSProps);
+}
+
+function uncast(val, typ) {
+    return transform(val, typ, jsToJSONProps);
+}
+
+function l(typ) {
+    return { literal: typ };
+}
+
+function a(typ) {
+    return { arrayItems: typ };
+}
+
+function u(...typs) {
+    return { unionMembers: typs };
+}
+
+function o(props, additional) {
+    return { props, additional };
+}
+
+function m(additional) {
+    const props = [];
+    return { props, additional };
+}
+
+function r(name) {
+    return { ref: name };
+}
+
+const typeMap = {
+    "TopLevel": o([
+        { json: "name", js: "name", typ: "" },
+    ], false),
+};
+
+module.exports = {
+    "topLevelToJson": topLevelToJson,
+    "toTopLevel": toTopLevel,
+};
diff --git a/head/schema-kotlin/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt b/head/schema-kotlin/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt
new file mode 100644
index 0000000..efb1442
--- /dev/null
+++ b/head/schema-kotlin/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt
@@ -0,0 +1,21 @@
+// To parse the JSON, install Klaxon and do:
+//
+//   val topLevel = TopLevel.fromJson(jsonString)
+
+package quicktype
+
+import com.beust.klaxon.*
+
+private val klaxon = Klaxon()
+
+class TopLevel(elements: Collection<SomeObject>) : ArrayList<SomeObject>(elements) {
+    public fun toJson() = klaxon.toJsonString(this)
+
+    companion object {
+        public fun fromJson(json: String) = TopLevel(klaxon.parseArray<SomeObject>(json)!!)
+    }
+}
+
+data class SomeObject (
+    val name: String
+)
diff --git a/head/schema-kotlin-jackson/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt b/head/schema-kotlin-jackson/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt
new file mode 100644
index 0000000..b836065
--- /dev/null
+++ b/head/schema-kotlin-jackson/test/inputs/schema/root-array-ref.schema/default/TopLevel.kt
@@ -0,0 +1,32 @@
+// To parse the JSON, install jackson-module-kotlin and do:
+//
+//   val topLevel = TopLevel.fromJson(jsonString)
+
+package quicktype
+
+import com.fasterxml.jackson.annotation.*
+import com.fasterxml.jackson.core.*
+import com.fasterxml.jackson.databind.*
+import com.fasterxml.jackson.databind.deser.std.StdDeserializer
+import com.fasterxml.jackson.databind.module.SimpleModule
+import com.fasterxml.jackson.databind.node.*
+import com.fasterxml.jackson.databind.ser.std.StdSerializer
+import com.fasterxml.jackson.module.kotlin.*
+
+val mapper = jacksonObjectMapper().apply {
+    propertyNamingStrategy = PropertyNamingStrategy.LOWER_CAMEL_CASE
+    setSerializationInclusion(JsonInclude.Include.NON_NULL)
+}
+
+class TopLevel(elements: Collection<SomeObject>) : ArrayList<SomeObject>(elements) {
+    fun toJson() = mapper.writeValueAsString(this)
+
+    companion object {
+        fun fromJson(json: String) = mapper.readValue<TopLevel>(json)
+    }
+}
+
+data class SomeObject (
+    @get:JsonProperty(required=true)@field:JsonProperty(required=true)
+    val name: String
+)
diff --git a/head/schema-pike/test/inputs/schema/root-array-ref.schema/default/TopLevel.pmod b/head/schema-pike/test/inputs/schema/root-array-ref.schema/default/TopLevel.pmod
new file mode 100644
index 0000000..9b8bcd5
--- /dev/null
+++ b/head/schema-pike/test/inputs/schema/root-array-ref.schema/default/TopLevel.pmod
@@ -0,0 +1,39 @@
+// This source has been automatically generated by quicktype.
+// ( https://github.com/quicktype/quicktype )
+//
+// To use this code, simply import it into your project as a Pike module.
+// To JSON-encode your object, you can pass it to `Standards.JSON.encode`
+// or call `encode_json` on it.
+//
+// To decode a JSON string, first pass it to `Standards.JSON.decode`,
+// and then pass the result to `<YourClass>_from_JSON`.
+// It will return an instance of <YourClass>.
+// Bear in mind that these functions have unexpected behavior,
+// and will likely throw an error, if the JSON string does not
+// match the expected interface, even if the JSON itself is valid.
+
+typedef array(SomeObject) TopLevel;
+
+TopLevel TopLevel_from_JSON(mixed json) {
+    return map(json, SomeObject_from_JSON);
+}
+
+class SomeObject {
+    string name; // json: "name"
+
+    string encode_json() {
+        mapping(string:mixed) json = ([
+            "name" : name,
+        ]);
+
+        return Standards.JSON.encode(json);
+    }
+}
+
+SomeObject SomeObject_from_JSON(mixed json) {
+    SomeObject retval = SomeObject();
+
+    retval.name = json["name"];
+
+    return retval;
+}
diff --git a/head/schema-python/test/inputs/schema/root-array-ref.schema/default/quicktype.py b/head/schema-python/test/inputs/schema/root-array-ref.schema/default/quicktype.py
new file mode 100644
index 0000000..de30973
--- /dev/null
+++ b/head/schema-python/test/inputs/schema/root-array-ref.schema/default/quicktype.py
@@ -0,0 +1,44 @@
+from dataclasses import dataclass
+from typing import Any, TypeVar, Callable, Type, cast
+
+
+T = TypeVar("T")
+
+
+def from_str(x: Any) -> str:
+    assert isinstance(x, str)
+    return x
+
+
+def from_list(f: Callable[[Any], T], x: Any) -> list[T]:
+    assert isinstance(x, list)
+    return [f(y) for y in x]
+
+
+def to_class(c: Type[T], x: Any) -> dict:
+    assert isinstance(x, c)
+    return cast(Any, x).to_dict()
+
+
+@dataclass
+class SomeObject:
+    name: str
+
+    @staticmethod
+    def from_dict(obj: Any) -> 'SomeObject':
+        assert isinstance(obj, dict)
+        name = from_str(obj.get("name"))
+        return SomeObject(name)
+
+    def to_dict(self) -> dict:
+        result: dict = {}
+        result["name"] = from_str(self.name)
+        return result
+
+
+def top_level_from_dict(s: Any) -> list[SomeObject]:
+    return from_list(SomeObject.from_dict, s)
+
+
+def top_level_to_dict(x: list[SomeObject]) -> Any:
+    return from_list(lambda x: to_class(SomeObject, x), x)
diff --git a/head/schema-ruby/test/inputs/schema/root-array-ref.schema/default/TopLevel.rb b/head/schema-ruby/test/inputs/schema/root-array-ref.schema/default/TopLevel.rb
new file mode 100644
index 0000000..1f3ed96
--- /dev/null
+++ b/head/schema-ruby/test/inputs/schema/root-array-ref.schema/default/TopLevel.rb
@@ -0,0 +1,55 @@
+# This code may look unusually verbose for Ruby (and it is), but
+# it performs some subtle and complex validation of JSON data.
+#
+# To parse this JSON, add 'dry-struct' and 'dry-types' gems, then do:
+#
+#   top_level = TopLevel.from_json! "[…]"
+#   puts top_level.first.some_object_name
+#
+# If from_json! succeeds, the value returned matches the schema.
+
+require 'json'
+require 'dry-types'
+require 'dry-struct'
+
+module Types
+  include Dry.Types(default: :nominal)
+
+  Hash   = Strict::Hash
+  String = Strict::String
+end
+
+class SomeObject < Dry::Struct
+  attribute :some_object_name, Types::String
+
+  def self.from_dynamic!(d)
+    d = Types::Hash[d]
+    new(
+      some_object_name: d.fetch("name"),
+    )
+  end
+
+  def self.from_json!(json)
+    from_dynamic!(JSON.parse(json))
+  end
+
+  def to_dynamic
+    {
+      "name" => some_object_name,
+    }
+  end
+
+  def to_json(options = nil)
+    JSON.generate(to_dynamic, options)
+  end
+end
+
+class TopLevel
+  def self.from_json!(json)
+    top_level = JSON.parse(json, quirks_mode: true).map { |x| SomeObject.from_dynamic!(x) }
+    top_level.define_singleton_method(:to_json) do
+      JSON.generate(self.map { |x| x.to_dynamic })
+    end
+    top_level
+  end
+end
diff --git a/head/schema-rust/test/inputs/schema/root-array-ref.schema/default/module_under_test.rs b/head/schema-rust/test/inputs/schema/root-array-ref.schema/default/module_under_test.rs
new file mode 100644
index 0000000..257f734
--- /dev/null
+++ b/head/schema-rust/test/inputs/schema/root-array-ref.schema/default/module_under_test.rs
@@ -0,0 +1,21 @@
+// Example code that deserializes and serializes the model.
+// extern crate serde;
+// #[macro_use]
+// extern crate serde_derive;
+// extern crate serde_json;
+//
+// use generated_module::TopLevel;
+//
+// fn main() {
+//     let json = r#"{"answer": 42}"#;
+//     let model: TopLevel = serde_json::from_str(&json).unwrap();
+// }
+
+use serde::{Serialize, Deserialize};
+
+pub type TopLevel = Vec<SomeObject>;
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct SomeObject {
+    pub name: String,
+}
diff --git a/head/schema-scala3/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala b/head/schema-scala3/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala
new file mode 100644
index 0000000..f2ea162
--- /dev/null
+++ b/head/schema-scala3/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala
@@ -0,0 +1,15 @@
+package quicktype
+
+import io.circe.syntax._
+import io.circe._
+import cats.syntax.functor._
+
+// If a union has a null in, then we'll need this too... 
+type NullValue = None.type
+
+type TopLevel = List[SomeObject]
+given (using ev : SomeObject): Encoder[Seq[SomeObject]] = Encoder.encodeSeq[SomeObject]
+
+case class SomeObject (
+    val name : String
+) derives Encoder.AsObject, Decoder
diff --git a/head/schema-scala3-upickle/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala b/head/schema-scala3-upickle/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala
new file mode 100644
index 0000000..9899d2d
--- /dev/null
+++ b/head/schema-scala3-upickle/test/inputs/schema/root-array-ref.schema/default/TopLevel.scala
@@ -0,0 +1,72 @@
+package quicktype
+
+// Custom pickler so that missing keys and JSON nulls both read as None,
+// and None is left out when writing (upickle's default for Option is a
+// JSON array).
+object OptionPickler extends upickle.AttributeTagged:
+    import upickle.default.Writer
+    import upickle.default.Reader
+    override implicit def OptionWriter[T: Writer]: Writer[Option[T]] =
+        implicitly[Writer[T]].comap[Option[T]] {
+            case None => null.asInstanceOf[T]
+            case Some(x) => x
+        }
+
+    override implicit def OptionReader[T: Reader]: Reader[Option[T]] = {
+        new Reader.Delegate[Any, Option[T]](implicitly[Reader[T]].map(Some(_))){
+        override def visitNull(index: Int) = None
+        }
+    }
+end OptionPickler
+
+// If a union has a null in, then we'll need this too...
+type NullValue = None.type
+given OptionPickler.ReadWriter[NullValue] = OptionPickler.readwriter[ujson.Value].bimap[NullValue](
+    _ => ujson.Null,
+    json => if json.isNull then None else throw new upickle.core.Abort("not null")
+)
+
+object JsonExt:
+    val valueReader = OptionPickler.readwriter[ujson.Value]
+
+    // upickle's built-in primitive readers are lenient -- the numeric and
+    // boolean readers accept strings, and the string reader accepts
+    // numbers and booleans -- so untagged unions need strict readers to
+    // pick the right member.
+    val strictString: OptionPickler.Reader[String] = valueReader.map {
+        case ujson.Str(s) => s
+        case json => throw new upickle.core.Abort("expected string, got " + json)
+    }
+    val strictLong: OptionPickler.Reader[Long] = valueReader.map {
+        case ujson.Num(n) if n.isWhole => n.toLong
+        case json => throw new upickle.core.Abort("expected integer, got " + json)
+    }
+    val strictDouble: OptionPickler.Reader[Double] = valueReader.map {
+        case ujson.Num(n) => n
+        case json => throw new upickle.core.Abort("expected number, got " + json)
+    }
+    val strictBoolean: OptionPickler.Reader[Boolean] = valueReader.map {
+        case ujson.Bool(b) => b
+        case json => throw new upickle.core.Abort("expected boolean, got " + json)
+    }
+
+    def badMerge[T](r1: => OptionPickler.Reader[?], rest: OptionPickler.Reader[?]*): OptionPickler.Reader[T] = valueReader.map { json =>
+        var t: T | Null = null
+        val stack       = Vector.newBuilder[Throwable]
+        (r1 +: rest).foreach { reader =>
+            if t == null then
+            try
+                t = OptionPickler.read[T](json, trace = true)(using reader.asInstanceOf[OptionPickler.Reader[T]])
+            catch
+                case exc => stack += exc
+        }
+        if t != null then t.nn else throw new Exception(json.toString(), stack.result().headOption.getOrElse(null))
+    }
+end JsonExt
+
+
+type TopLevel = List[SomeObject]
+
+case class SomeObject (
+    val name : String
+) derives OptionPickler.ReadWriter
diff --git a/head/schema-schema/test/inputs/schema/root-array-ref.schema/default/TopLevel.schema b/head/schema-schema/test/inputs/schema/root-array-ref.schema/default/TopLevel.schema
new file mode 100644
index 0000000..71485e2
--- /dev/null
+++ b/head/schema-schema/test/inputs/schema/root-array-ref.schema/default/TopLevel.schema
@@ -0,0 +1,22 @@
+{
+    "$schema": "http://json-schema.org/draft-06/schema#",
+    "type": "array",
+    "items": {
+        "$ref": "#/definitions/SomeObject"
+    },
+    "definitions": {
+        "SomeObject": {
+            "type": "object",
+            "additionalProperties": false,
+            "properties": {
+                "name": {
+                    "type": "string"
+                }
+            },
+            "required": [
+                "name"
+            ],
+            "title": "SomeObject"
+        }
+    }
+}
diff --git a/base/schema-typescript/test/inputs/schema/issue2680-top-level-array.schema/default/TopLevel.ts b/head/schema-typescript/test/inputs/schema/issue2680-top-level-array.schema/default/TopLevel.ts
index 9d6098b..e78dc5c 100644
--- a/base/schema-typescript/test/inputs/schema/issue2680-top-level-array.schema/default/TopLevel.ts
+++ b/head/schema-typescript/test/inputs/schema/issue2680-top-level-array.schema/default/TopLevel.ts
@@ -1,20 +1,22 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
+export type TopLevel = number[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): number[] {
+    public static toTopLevel(json: string): TopLevel {
         return cast(JSON.parse(json), a(0));
     }
 
-    public static topLevelToJson(value: number[]): string {
+    public static topLevelToJson(value: TopLevel): string {
         return JSON.stringify(uncast(value, a(0)), null, 2);
     }
 }
diff --git a/head/schema-typescript/test/inputs/schema/root-array-ref.schema/default/TopLevel.ts b/head/schema-typescript/test/inputs/schema/root-array-ref.schema/default/TopLevel.ts
new file mode 100644
index 0000000..5dce22c
--- /dev/null
+++ b/head/schema-typescript/test/inputs/schema/root-array-ref.schema/default/TopLevel.ts
@@ -0,0 +1,185 @@
+// To parse this data:
+//
+//   import { Convert, TopLevel } from "./TopLevel";
+//
+//   const topLevel = Convert.toTopLevel(json);
+//
+// These functions will throw an error if the JSON doesn't
+// match the expected interface, even if the JSON is valid.
+
+export interface SomeObject {
+    name: string;
+}
+
+export type TopLevel = SomeObject[];
+
+// Converts JSON strings to/from your types
+// and asserts the results of JSON.parse at runtime
+export class Convert {
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("SomeObject")));
+    }
+
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("SomeObject"))), null, 2);
+    }
+}
+
+function invalidValue(typ: any, val: any, key: any, parent: any = ''): never {
+    const prettyTyp = prettyTypeName(typ);
+    const parentText = parent ? ` on ${parent}` : '';
+    const keyText = key ? ` for key "${key}"` : '';
+    throw Error(`Invalid value${keyText}${parentText}. Expected ${prettyTyp} but got ${JSON.stringify(val)}`);
+}
+
+function prettyTypeName(typ: any): string {
+    if (Array.isArray(typ)) {
+        if (typ.length === 2 && typ[0] === undefined) {
+            return `an optional ${prettyTypeName(typ[1])}`;
+        } else {
+            return `one of [${typ.map(a => { return prettyTypeName(a); }).join(", ")}]`;
+        }
+    } else if (typeof typ === "object" && typ.literal !== undefined) {
+        return typ.literal;
+    } else {
+        return typeof typ;
+    }
+}
+
+function jsonToJSProps(typ: any): any {
+    if (typ.jsonToJS === undefined) {
+        const map: any = {};
+        typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
+        typ.jsonToJS = map;
+    }
+    return typ.jsonToJS;
+}
+
+function jsToJSONProps(typ: any): any {
+    if (typ.jsToJSON === undefined) {
+        const map: any = {};
+        typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
+        typ.jsToJSON = map;
+    }
+    return typ.jsToJSON;
+}
+
+function transform(val: any, typ: any, getProps: any, key: any = '', parent: any = ''): any {
+    function transformPrimitive(typ: string, val: any): any {
+        if (typeof typ === typeof val) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+
+    function transformUnion(typs: any[], val: any): any {
+        // val must validate against one typ in typs
+        const l = typs.length;
+        for (let i = 0; i < l; i++) {
+            const typ = typs[i];
+            try {
+                return transform(val, typ, getProps);
+            } catch (_) {}
+        }
+        return invalidValue(typs, val, key, parent);
+    }
+
+    function transformEnum(cases: string[], val: any): any {
+        if (cases.indexOf(val) !== -1) return val;
+        return invalidValue(cases.map(a => { return l(a); }), val, key, parent);
+    }
+
+    function transformArray(typ: any, val: any): any {
+        // val must be an array with no invalid elements
+        if (!Array.isArray(val)) return invalidValue(l("array"), val, key, parent);
+        return val.map(el => transform(el, typ, getProps));
+    }
+
+    function transformDate(val: any): any {
+        if (val === null) {
+            return null;
+        }
+        const d = new Date(val);
+        if (isNaN(d.valueOf())) {
+            return invalidValue(l("Date"), val, key, parent);
+        }
+        return d;
+    }
+
+    function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
+        if (val === null || typeof val !== "object" || Array.isArray(val)) {
+            return invalidValue(l(ref || "object"), val, key, parent);
+        }
+        const result: any = {};
+        Object.getOwnPropertyNames(props).forEach(key => {
+            const prop = props[key];
+            const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
+            result[prop.key] = transform(v, prop.typ, getProps, key, ref);
+        });
+        Object.getOwnPropertyNames(val).forEach(key => {
+            if (!Object.prototype.hasOwnProperty.call(props, key)) {
+                result[key] = transform(val[key], additional, getProps, key, ref);
+            }
+        });
+        return result;
+    }
+
+    if (typ === "any") return val;
+    if (typ === null) {
+        if (val === null) return val;
+        return invalidValue(typ, val, key, parent);
+    }
+    if (typ === false) return invalidValue(typ, val, key, parent);
+    let ref: any = undefined;
+    while (typeof typ === "object" && typ.ref !== undefined) {
+        ref = typ.ref;
+        typ = typeMap[typ.ref];
+    }
+    if (Array.isArray(typ)) return transformEnum(typ, val);
+    if (typeof typ === "object") {
+        return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
+            : typ.hasOwnProperty("arrayItems")    ? transformArray(typ.arrayItems, val)
+            : typ.hasOwnProperty("props")         ? transformObject(getProps(typ), typ.additional, val)
+            : invalidValue(typ, val, key, parent);
+    }
+    // Numbers can be parsed by Date but shouldn't be.
+    if (typ === Date && typeof val !== "number") return transformDate(val);
+    return transformPrimitive(typ, val);
+}
+
+function cast<T>(val: any, typ: any): T {
+    return transform(val, typ, jsonToJSProps);
+}
+
+function uncast<T>(val: T, typ: any): any {
+    return transform(val, typ, jsToJSONProps);
+}
+
+function l(typ: any) {
+    return { literal: typ };
+}
+
+function a(typ: any) {
+    return { arrayItems: typ };
+}
+
+function u(...typs: any[]) {
+    return { unionMembers: typs };
+}
+
+function o(props: any[], additional: any) {
+    return { props, additional };
+}
+
+function m(additional: any) {
+    const props: any[] = [];
+    return { props, additional };
+}
+
+function r(name: string) {
+    return { ref: name };
+}
+
+const typeMap: any = {
+    "SomeObject": o([
+        { json: "name", js: "name", typ: "" },
+    ], false),
+};
diff --git a/base/schema-typescript/test/inputs/schema/union.schema/default/TopLevel.ts b/head/schema-typescript/test/inputs/schema/union.schema/default/TopLevel.ts
index 35fee9c..c0c065e 100644
--- a/base/schema-typescript/test/inputs/schema/union.schema/default/TopLevel.ts
+++ b/head/schema-typescript/test/inputs/schema/union.schema/default/TopLevel.ts
@@ -1,28 +1,30 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     one?:   number;
     two:    boolean;
     three?: number;
     [property: string]: unknown;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -180,7 +182,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "one", js: "one", typ: u(undefined, 0) },
         { json: "two", js: "two", typ: true },
         { json: "three", js: "three", typ: u(undefined, 3.14) },
diff --git a/base/typescript/test/inputs/json/misc/00c36.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/00c36.json/default/TopLevel.ts
index ec3ba2b..712f14b 100644
--- a/base/typescript/test/inputs/json/misc/00c36.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/00c36.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     country:   Country;
     date:      string;
     decimal:   string;
@@ -26,22 +26,24 @@ export type ID = "US" | "NY.GDP.MKTP.CD";
 
 export type Value = "United States" | "GDP (current US$)";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "country", js: "country", typ: r("Country") },
         { json: "date", js: "date", typ: "" },
         { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/010b1.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/010b1.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/010b1.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/010b1.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/050b0.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/050b0.json/default/TopLevel.ts
index 3a81c70..0b2b3f7 100644
--- a/base/typescript/test/inputs/json/misc/050b0.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/050b0.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -49,15 +49,17 @@ export type MediaType = "text/html" | "text/plain";
 
 export type Title = "HTML" | "Plain Text";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -215,7 +217,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/06bee.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/06bee.json/default/TopLevel.ts
index f6d8b99..0afb133 100644
--- a/base/typescript/test/inputs/json/misc/06bee.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/06bee.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -44,15 +44,17 @@ export type MediaType = "text/html";
 
 export type Title = "HTML";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -210,7 +212,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/07c75.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/07c75.json/default/TopLevel.ts
index 3fca6b7..eb3d0d6 100644
--- a/base/typescript/test/inputs/json/misc/07c75.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/07c75.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      string[];
@@ -34,15 +34,17 @@ export interface Text {
     url:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -200,7 +202,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a("") },
diff --git a/base/typescript/test/inputs/json/misc/0a91a.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/0a91a.json/default/TopLevel.ts
index fcc76df..495beb2 100644
--- a/base/typescript/test/inputs/json/misc/0a91a.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/0a91a.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     actor:      Actor;
     created_at: Date;
     id:         string;
@@ -224,15 +224,17 @@ export interface TopLevelRepo {
 
 export type Type = "PushEvent" | "CreateEvent" | "WatchEvent" | "PullRequestEvent" | "DeleteEvent";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -390,7 +392,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "actor", js: "actor", typ: r("Actor") },
         { json: "created_at", js: "created_at", typ: Date },
         { json: "id", js: "id", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/10be4.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/10be4.json/default/TopLevel.ts
index 72874a8..38ba6eb 100644
--- a/base/typescript/test/inputs/json/misc/10be4.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/10be4.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -49,15 +49,17 @@ export type MediaType = "text/html" | "text/plain" | "application/pdf";
 
 export type Title = "HTML" | "Plain Text" | "PDF";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -215,7 +217,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/13d8d.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/13d8d.json/default/TopLevel.ts
index 63d7b44..cc9ac3f 100644
--- a/base/typescript/test/inputs/json/misc/13d8d.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/13d8d.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     category:         string;
     context:          string;
     id:               number;
@@ -35,15 +35,17 @@ export interface OutcomeStatus {
     date:     string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -201,7 +203,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "category", js: "category", typ: "" },
         { json: "context", js: "context", typ: "" },
         { json: "id", js: "id", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/1a7f5.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/1a7f5.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/1a7f5.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/1a7f5.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/2df80.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/2df80.json/default/TopLevel.ts
index 3579b5f..b1ea447 100644
--- a/base/typescript/test/inputs/json/misc/2df80.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/2df80.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     adminregion: Adminregion;
     capitalCity: string;
     id:          string;
@@ -31,22 +31,24 @@ export type ID = "" | "SAS" | "SSA" | "ECA" | "LAC" | "EAP" | "MNA" | "HIC" | "L
 
 export type Value = "" | "South Asia" | "Sub-Saharan Africa (excluding high income)" | "Europe & Central Asia (excluding high income)" | "Latin America & Caribbean (excluding high income)" | "East Asia & Pacific (excluding high income)" | "Middle East & North Africa (excluding high income)" | "High income" | "Low income" | "Aggregates" | "Lower middle income" | "Upper middle income" | "Not classified" | "IDA" | "IBRD" | "Blend" | "Latin America & Caribbean " | "Sub-Saharan Africa " | "Europe & Central Asia" | "Middle East & North Africa" | "East Asia & Pacific" | "North America";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -204,7 +206,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "adminregion", js: "adminregion", typ: r("Adminregion") },
         { json: "capitalCity", js: "capitalCity", typ: "" },
         { json: "id", js: "id", typ: "" },
@@ -220,7 +222,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/32d5c.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/32d5c.json/default/TopLevel.ts
index 46f2be2..3dd60f6 100644
--- a/base/typescript/test/inputs/json/misc/32d5c.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/32d5c.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     BirthDate:            Date | null;
     BirthDateIsProtected: boolean;
     GenderTypeID:         number;
@@ -18,15 +18,17 @@ export interface TopLevel {
     PreferredName:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "BirthDate", js: "BirthDate", typ: u(Date, null) },
         { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true },
         { json: "GenderTypeID", js: "GenderTypeID", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/3536b.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/3536b.json/default/TopLevel.ts
index 5572056..08ee149 100644
--- a/base/typescript/test/inputs/json/misc/3536b.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/3536b.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -38,15 +38,17 @@ export interface Text {
     url:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -204,7 +206,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/43970.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/43970.json/default/TopLevel.ts
index 045cf4c..99bc191 100644
--- a/base/typescript/test/inputs/json/misc/43970.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/43970.json/default/TopLevel.ts
@@ -1,27 +1,29 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     ID:    number;
     Name:  string;
     Notes: string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -179,7 +181,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "ID", js: "ID", typ: 0 },
         { json: "Name", js: "Name", typ: "" },
         { json: "Notes", js: "Notes", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/570ec.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/570ec.json/default/TopLevel.ts
index 8f9efcb..9d49e34 100644
--- a/base/typescript/test/inputs/json/misc/570ec.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/570ec.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      string[];
@@ -41,15 +41,17 @@ export interface Text {
     url:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -207,7 +209,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a("") },
diff --git a/base/typescript/test/inputs/json/misc/5eae5.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/5eae5.json/default/TopLevel.ts
index 6c1cb4f..193dd5c 100644
--- a/base/typescript/test/inputs/json/misc/5eae5.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/5eae5.json/default/TopLevel.ts
@@ -1,28 +1,30 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     Date:    Date;
     ID:      number;
     Sponsor: string;
     Title:   string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -180,7 +182,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "Date", js: "Date", typ: Date },
         { json: "ID", js: "ID", typ: 0 },
         { json: "Sponsor", js: "Sponsor", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/66121.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/66121.json/default/TopLevel.ts
index f3d3c7a..8311b62 100644
--- a/base/typescript/test/inputs/json/misc/66121.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/66121.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -44,15 +44,17 @@ export type MediaType = "text/html";
 
 export type Title = "HTML";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -210,7 +212,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/6eb00.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/6eb00.json/default/TopLevel.ts
index 5c6df64..4cf9480 100644
--- a/base/typescript/test/inputs/json/misc/6eb00.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/6eb00.json/default/TopLevel.ts
@@ -1,27 +1,29 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     DirectorateID: number;
     Id:            number;
     Name:          string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -179,7 +181,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "DirectorateID", js: "DirectorateID", typ: 0 },
         { json: "Id", js: "Id", typ: 0 },
         { json: "Name", js: "Name", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/77392.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/77392.json/default/TopLevel.ts
index bd22f57..182a918 100644
--- a/base/typescript/test/inputs/json/misc/77392.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/77392.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     designation:    string;
     discovery_date: Date;
     h_mag?:         string;
@@ -24,15 +24,17 @@ export type OrbitClass = "Apollo" | "Amor" | "Aten" | "Comet" | "Jupiter-family
 
 export type Pha = "Y" | "N" | "n/a";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -190,7 +192,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "designation", js: "designation", typ: "" },
         { json: "discovery_date", js: "discovery_date", typ: Date },
         { json: "h_mag", js: "h_mag", typ: u(undefined, "") },
diff --git a/base/typescript/test/inputs/json/misc/7f568.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/7f568.json/default/TopLevel.ts
index 9811c74..9c12162 100644
--- a/base/typescript/test/inputs/json/misc/7f568.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/7f568.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     comments:     number;
     comments_url: string;
     commits_url:  string;
@@ -38,15 +38,17 @@ export type Language = "Markdown";
 
 export type Type = "text/plain";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -204,7 +206,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "comments", js: "comments", typ: 0 },
         { json: "comments_url", js: "comments_url", typ: "" },
         { json: "commits_url", js: "commits_url", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/7fbfb.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/7fbfb.json/default/TopLevel.ts
index 98ac0ff..3009fd9 100644
--- a/base/typescript/test/inputs/json/misc/7fbfb.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/7fbfb.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     country:   Country;
     date:      string;
     decimal:   string;
@@ -26,22 +26,24 @@ export type ID = "CN" | "NY.GDP.MKTP.CD";
 
 export type Value = "China" | "GDP (current US$)";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "country", js: "country", typ: r("Country") },
         { json: "date", js: "date", typ: "" },
         { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/9847b.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/9847b.json/default/TopLevel.ts
index 9aee0ae..15cb8fe 100644
--- a/base/typescript/test/inputs/json/misc/9847b.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/9847b.json/default/TopLevel.ts
@@ -1,26 +1,28 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:   string;
     name: string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -178,7 +180,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "name", js: "name", typ: "" },
     ], false),
diff --git a/base/typescript/test/inputs/json/misc/996bd.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/996bd.json/default/TopLevel.ts
index 45af1cc..5ff3886 100644
--- a/base/typescript/test/inputs/json/misc/996bd.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/996bd.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -42,15 +42,17 @@ export type MediaType = "text/plain" | "text/html";
 
 export type Title = "Plain Text" | "HTML";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -208,7 +210,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/9a503.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/9a503.json/default/TopLevel.ts
index c0ee0ae..4b5d75a 100644
--- a/base/typescript/test/inputs/json/misc/9a503.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/9a503.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -36,15 +36,17 @@ export interface Text {
     url:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -202,7 +204,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/9eed5.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/9eed5.json/default/TopLevel.ts
index 18cf5a2..704822b 100644
--- a/base/typescript/test/inputs/json/misc/9eed5.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/9eed5.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -36,15 +36,17 @@ export interface Text {
     url:        string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -202,7 +204,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/a45b0.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/a45b0.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/a45b0.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/a45b0.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/ab0d1.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/ab0d1.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/ab0d1.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/ab0d1.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/ad8be.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/ad8be.json/default/TopLevel.ts
index 72874a8..38ba6eb 100644
--- a/base/typescript/test/inputs/json/misc/ad8be.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/ad8be.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:            string;
     identifiers:   Identifier[];
     keywords:      Keyword[];
@@ -49,15 +49,17 @@ export type MediaType = "text/html" | "text/plain" | "application/pdf";
 
 export type Title = "HTML" | "Plain Text" | "PDF";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -215,7 +217,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
         { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
diff --git a/base/typescript/test/inputs/json/misc/b4865.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/b4865.json/default/TopLevel.ts
index 29944d2..6b341a1 100644
--- a/base/typescript/test/inputs/json/misc/b4865.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/b4865.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     ":@computed_region_cbhk_fwbd"?: string;
     ":@computed_region_nnqa_25f4"?: string;
     fall:                           Fall;
@@ -33,15 +33,17 @@ export type Type = "Point";
 
 export type Nametype = "Valid";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") },
         { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") },
         { json: "fall", js: "fall", typ: r("Fall") },
diff --git a/base/typescript/test/inputs/json/misc/c8c7e.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/c8c7e.json/default/TopLevel.ts
index ebf76ed..44496f2 100644
--- a/base/typescript/test/inputs/json/misc/c8c7e.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/c8c7e.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     country:   Country;
     date:      string;
     decimal:   string;
@@ -26,22 +26,24 @@ export type ID = "IN" | "NY.GDP.MKTP.CD";
 
 export type Value = "India" | "GDP (current US$)";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "country", js: "country", typ: r("Country") },
         { json: "date", js: "date", typ: "" },
         { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/cda6c.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/cda6c.json/default/TopLevel.ts
index 0f8ebec..fe92ede 100644
--- a/base/typescript/test/inputs/json/misc/cda6c.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/cda6c.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     country:   Country;
     date:      string;
     decimal:   string;
@@ -26,22 +26,24 @@ export type ID = "CN" | "SP.POP.TOTL";
 
 export type Value = "China" | "Population, total";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "country", js: "country", typ: r("Country") },
         { json: "date", js: "date", typ: "" },
         { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/e2a58.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/e2a58.json/default/TopLevel.ts
index 3bc7cba..ddf1d9b 100644
--- a/base/typescript/test/inputs/json/misc/e2a58.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/e2a58.json/default/TopLevel.ts
@@ -1,26 +1,28 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     date:              string;
     "stop-and-search": string[];
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -178,7 +180,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "date", js: "date", typ: "" },
         { json: "stop-and-search", js: "stop-and-search", typ: a("") },
     ], false),
diff --git a/base/typescript/test/inputs/json/misc/e53b5.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/e53b5.json/default/TopLevel.ts
index 1a8cc5b..8aa1ffb 100644
--- a/base/typescript/test/inputs/json/misc/e53b5.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/e53b5.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     country:   Country;
     date:      string;
     decimal:   string;
@@ -26,22 +26,24 @@ export type ID = "IN" | "SP.POP.TOTL";
 
 export type Value = "India" | "Population, total";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     page:     number;
     pages:    number;
     per_page: string;
     total:    number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
     }
 }
 
@@ -199,7 +201,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "country", js: "country", typ: r("Country") },
         { json: "date", js: "date", typ: "" },
         { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
         { json: "id", js: "id", typ: r("ID") },
         { json: "value", js: "value", typ: r("Value") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "page", js: "page", typ: 0 },
         { json: "pages", js: "pages", typ: 0 },
         { json: "per_page", js: "per_page", typ: "" },
diff --git a/base/typescript/test/inputs/json/misc/e8a0b.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/e8a0b.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/e8a0b.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/e8a0b.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/e8b04.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/e8b04.json/default/TopLevel.ts
index 5e257c6..dec9294 100644
--- a/base/typescript/test/inputs/json/misc/e8b04.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/e8b04.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     averageRating:            number;
     category?:                string;
     createdAt:                number;
@@ -240,15 +240,17 @@ export interface TableAuthor {
 
 export type ViewType = "tabular";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -406,7 +408,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "averageRating", js: "averageRating", typ: 0 },
         { json: "category", js: "category", typ: u(undefined, "") },
         { json: "createdAt", js: "createdAt", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/f3139.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/f3139.json/default/TopLevel.ts
index 9aee0ae..15cb8fe 100644
--- a/base/typescript/test/inputs/json/misc/f3139.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/f3139.json/default/TopLevel.ts
@@ -1,26 +1,28 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     id:   string;
     name: string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -178,7 +180,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "id", js: "id", typ: "" },
         { json: "name", js: "name", typ: "" },
     ], false),
diff --git a/base/typescript/test/inputs/json/misc/f3edf.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/f3edf.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/f3edf.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/f3edf.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/misc/f466a.json/default/TopLevel.ts b/head/typescript/test/inputs/json/misc/f466a.json/default/TopLevel.ts
index a94487f..258ae48 100644
--- a/base/typescript/test/inputs/json/misc/f466a.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/misc/f466a.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     age:     number;
     country: Country;
     females: number;
@@ -18,15 +18,17 @@ export interface TopLevel {
 
 export type Country = "United States";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -184,7 +186,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "age", js: "age", typ: 0 },
         { json: "country", js: "country", typ: r("Country") },
         { json: "females", js: "females", typ: 0 },
diff --git a/base/typescript/test/inputs/json/priority/bug863.json/default/TopLevel.ts b/head/typescript/test/inputs/json/priority/bug863.json/default/TopLevel.ts
index 92f7813..efed975 100644
--- a/base/typescript/test/inputs/json/priority/bug863.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/priority/bug863.json/default/TopLevel.ts
@@ -1,15 +1,15 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export type TopLevel = TopLevelElement[] | PurpleTopLevel | string;
+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel | string;
 
-export interface TopLevelElement {
+export interface PurpleTopLevel {
     ALIENLEVEL:          number;
     BREED:               Breed;
     CHAR_DIMENSION:      number;
@@ -41,7 +41,7 @@ export type RankTitle = "President" | "Advisor" | "Veteran" | "Applicant";
 
 export type Sex = "Neuter" | "Male" | "Female";
 
-export interface PurpleTopLevel {
+export interface FluffyTopLevel {
     ADVENTURERCOUNT: number;
     AGENTCOUNT:      number;
     ATROXCOUNT:      number;
@@ -79,15 +79,17 @@ export interface PurpleTopLevel {
     TRADERCOUNT:     number;
 }
 
+export type TopLevel = TopLevelUnion[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), "")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), "")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2);
     }
 }
 
@@ -245,7 +247,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevelElement": o([
+    "PurpleTopLevel": o([
         { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 },
         { json: "BREED", js: "BREED", typ: r("Breed") },
         { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 },
@@ -264,7 +266,7 @@ const typeMap: any = {
         { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") },
         { json: "SEX", js: "SEX", typ: r("Sex") },
     ], false),
-    "PurpleTopLevel": o([
+    "FluffyTopLevel": o([
         { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 },
         { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 },
         { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 },
diff --git a/base/typescript/test/inputs/json/priority/issue2680-object-array.json/default/TopLevel.ts b/head/typescript/test/inputs/json/priority/issue2680-object-array.json/default/TopLevel.ts
index 879709d..42a6543 100644
--- a/base/typescript/test/inputs/json/priority/issue2680-object-array.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/priority/issue2680-object-array.json/default/TopLevel.ts
@@ -1,25 +1,27 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     key: string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -177,7 +179,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "key", js: "key", typ: "" },
     ], false),
 };
diff --git a/base/typescript/test/inputs/json/priority/issue2680-scalar-array.json/default/TopLevel.ts b/head/typescript/test/inputs/json/priority/issue2680-scalar-array.json/default/TopLevel.ts
index 9d6098b..e78dc5c 100644
--- a/base/typescript/test/inputs/json/priority/issue2680-scalar-array.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/priority/issue2680-scalar-array.json/default/TopLevel.ts
@@ -1,20 +1,22 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
+export type TopLevel = number[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): number[] {
+    public static toTopLevel(json: string): TopLevel {
         return cast(JSON.parse(json), a(0));
     }
 
-    public static topLevelToJson(value: number[]): string {
+    public static topLevelToJson(value: TopLevel): string {
         return JSON.stringify(uncast(value, a(0)), null, 2);
     }
 }
diff --git a/base/typescript/test/inputs/json/priority/kotlin-enum-class-case-collision.json/default/TopLevel.ts b/head/typescript/test/inputs/json/priority/kotlin-enum-class-case-collision.json/default/TopLevel.ts
index 4e8955f..87e24a8 100644
--- a/base/typescript/test/inputs/json/priority/kotlin-enum-class-case-collision.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/priority/kotlin-enum-class-case-collision.json/default/TopLevel.ts
@@ -1,27 +1,29 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     category: Category;
 }
 
 export type Category = " " | "";
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -179,7 +181,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "category", js: "category", typ: r("Category") },
     ], false),
     "Category": [
diff --git a/base/typescript/test/inputs/json/priority/optional-union.json/default/TopLevel.ts b/head/typescript/test/inputs/json/priority/optional-union.json/default/TopLevel.ts
index ed45e67..d8f890b 100644
--- a/base/typescript/test/inputs/json/priority/optional-union.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/priority/optional-union.json/default/TopLevel.ts
@@ -1,27 +1,29 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     a?: A;
 }
 
 export type A = number | string;
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -179,7 +181,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "a", js: "a", typ: u(undefined, u(0, "")) },
     ], false),
 };
diff --git a/base/typescript/test/inputs/json/samples/github-events.json/default/TopLevel.ts b/head/typescript/test/inputs/json/samples/github-events.json/default/TopLevel.ts
index 68bdc1c..86dcde6 100644
--- a/base/typescript/test/inputs/json/samples/github-events.json/default/TopLevel.ts
+++ b/head/typescript/test/inputs/json/samples/github-events.json/default/TopLevel.ts
@@ -1,13 +1,13 @@
 // To parse this data:
 //
-//   import { Convert } from "./TopLevel";
+//   import { Convert, TopLevel } from "./TopLevel";
 //
 //   const topLevel = Convert.toTopLevel(json);
 //
 // These functions will throw an error if the JSON doesn't
 // match the expected interface, even if the JSON is valid.
 
-export interface TopLevel {
+export interface TopLevelElement {
     actor:      Actor;
     created_at: Date;
     id:         string;
@@ -295,15 +295,17 @@ export interface TopLevelRepo {
     url:  string;
 }
 
+export type TopLevel = TopLevelElement[];
+
 // Converts JSON strings to/from your types
 // and asserts the results of JSON.parse at runtime
 export class Convert {
-    public static toTopLevel(json: string): TopLevel[] {
-        return cast(JSON.parse(json), a(r("TopLevel")));
+    public static toTopLevel(json: string): TopLevel {
+        return cast(JSON.parse(json), a(r("TopLevelElement")));
     }
 
-    public static topLevelToJson(value: TopLevel[]): string {
-        return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
+    public static topLevelToJson(value: TopLevel): string {
+        return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
     }
 }
 
@@ -461,7 +463,7 @@ function r(name: string) {
 }
 
 const typeMap: any = {
-    "TopLevel": o([
+    "TopLevelElement": o([
         { json: "actor", js: "actor", typ: r("Actor") },
         { json: "created_at", js: "created_at", typ: Date },
         { json: "id", js: "id", typ: "" },
