Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
43test cases
128files differ
128modified
0new
0deleted
1,530changed lines
+851 −679insertions / deletions
Base 7d9a8a7daad9eb226beaba6cdbb89b26884ccbce · PR merge c70e3d5e7251145beb6ba6282eb1f960cc8766dc · Head 39d6c7657be183570bd34487f1abedb96656b738 · raw patch
Test case

test/inputs/json/misc/00c36.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 country: Country;
1618 date: string;
1719 decimal: string;
@@ -32,7 +34,7 @@ export type Value =
3234 "United States"
3335 | "GDP (current US$)";
3436
35-export type PurpleTopLevel = {
37+export type FluffyTopLevel = {
3638 page: number;
3739 pages: number;
3840 per_page: string;
@@ -41,12 +43,12 @@ export type PurpleTopLevel = {
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+function toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+function topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevelElement": o([
208+ "PurpleTopLevel": o([
207209 { json: "country", js: "country", typ: r("Country") },
208210 { json: "date", js: "date", typ: "" },
209211 { json: "decimal", js: "decimal", typ: "" },
@@ -214,7 +216,7 @@ const typeMap: any = {
214216 { json: "id", js: "id", typ: r("ID") },
215217 { json: "value", js: "value", typ: r("Value") },
216218 ], false),
217- "PurpleTopLevel": o([
219+ "FluffyTopLevel": o([
218220 { json: "page", js: "page", typ: 0 },
219221 { json: "pages", js: "pages", typ: 0 },
220222 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "country", js: "country", typ: r("Country") },
176176 { json: "date", js: "date", typ: "" },
177177 { json: "decimal", js: "decimal", typ: "" },
@@ -182,7 +182,7 @@ const typeMap = {
182182 { json: "id", js: "id", typ: r("ID") },
183183 { json: "value", js: "value", typ: r("Value") },
184184 ], false),
185- "PurpleTopLevel": o([
185+ "FluffyTopLevel": o([
186186 { json: "page", js: "page", typ: 0 },
187187 { json: "pages", js: "pages", typ: 0 },
188188 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 country: Country;
1416 date: string;
1517 decimal: string;
@@ -26,7 +28,7 @@ export type ID = "US" | "NY.GDP.MKTP.CD";
2628
2729 export type Value = "United States" | "GDP (current US$)";
2830
29-export interface PurpleTopLevel {
31+export interface FluffyTopLevel {
3032 page: number;
3133 pages: number;
3234 per_page: string;
@@ -36,12 +38,12 @@ export interface PurpleTopLevel {
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
41+ public static toTopLevel(json: string): TopLevelUnion[] {
42+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
45+ public static topLevelToJson(value: TopLevelUnion[]): string {
46+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevelElement": o([
204+ "PurpleTopLevel": o([
203205 { json: "country", js: "country", typ: r("Country") },
204206 { json: "date", js: "date", typ: "" },
205207 { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
210212 { json: "id", js: "id", typ: r("ID") },
211213 { json: "value", js: "value", typ: r("Value") },
212214 ], false),
213- "PurpleTopLevel": o([
215+ "FluffyTopLevel": o([
214216 { json: "page", js: "page", typ: 0 },
215217 { json: "pages", js: "pages", typ: 0 },
216218 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/010b1.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/050b0.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -69,12 +71,12 @@ export type Title =
6971
7072 // Converts JSON strings to/from your types
7173 // and asserts the results of JSON.parse at runtime
72-function toTopLevel(json: string): TopLevel[] {
73- return cast(JSON.parse(json), a(r("TopLevel")));
74+function toTopLevel(json: string): TopLevelElement[] {
75+ return cast(JSON.parse(json), a(r("TopLevelElement")));
7476 }
7577
76-function topLevelToJson(value: TopLevel[]): string {
77- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
78+function topLevelToJson(value: TopLevelElement[]): string {
79+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
7880 }
7981
8082 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -231,7 +233,7 @@ function r(name: string) {
231233 }
232234
233235 const typeMap: any = {
234- "TopLevel": o([
236+ "TopLevelElement": o([
235237 { json: "id", js: "id", typ: "" },
236238 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
237239 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text";
5254 // Converts JSON strings to/from your types
5355 // and asserts the results of JSON.parse at runtime
5456 export class Convert {
55- public static toTopLevel(json: string): TopLevel[] {
56- return cast(JSON.parse(json), a(r("TopLevel")));
57+ public static toTopLevel(json: string): TopLevelElement[] {
58+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5759 }
5860
59- public static topLevelToJson(value: TopLevel[]): string {
60- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
61+ public static topLevelToJson(value: TopLevelElement[]): string {
62+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6163 }
6264 }
6365
@@ -215,7 +217,7 @@ function r(name: string) {
215217 }
216218
217219 const typeMap: any = {
218- "TopLevel": o([
220+ "TopLevelElement": o([
219221 { json: "id", js: "id", typ: "" },
220222 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
221223 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/06bee.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -57,12 +59,12 @@ export type Title =
5759
5860 // Converts JSON strings to/from your types
5961 // and asserts the results of JSON.parse at runtime
60-function toTopLevel(json: string): TopLevel[] {
61- return cast(JSON.parse(json), a(r("TopLevel")));
62+function toTopLevel(json: string): TopLevelElement[] {
63+ return cast(JSON.parse(json), a(r("TopLevelElement")));
6264 }
6365
64-function topLevelToJson(value: TopLevel[]): string {
65- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
66+function topLevelToJson(value: TopLevelElement[]): string {
67+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6668 }
6769
6870 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -219,7 +221,7 @@ function r(name: string) {
219221 }
220222
221223 const typeMap: any = {
222- "TopLevel": o([
224+ "TopLevelElement": o([
223225 { json: "id", js: "id", typ: "" },
224226 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
225227 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -47,12 +49,12 @@ export type Title = "HTML";
4749 // Converts JSON strings to/from your types
4850 // and asserts the results of JSON.parse at runtime
4951 export class Convert {
50- public static toTopLevel(json: string): TopLevel[] {
51- return cast(JSON.parse(json), a(r("TopLevel")));
52+ public static toTopLevel(json: string): TopLevelElement[] {
53+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5254 }
5355
54- public static topLevelToJson(value: TopLevel[]): string {
55- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
56+ public static topLevelToJson(value: TopLevelElement[]): string {
57+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5658 }
5759 }
5860
@@ -210,7 +212,7 @@ function r(name: string) {
210212 }
211213
212214 const typeMap: any = {
213- "TopLevel": o([
215+ "TopLevelElement": o([
214216 { json: "id", js: "id", typ: "" },
215217 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
216218 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/07c75.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: string[];
@@ -38,12 +40,12 @@ export type Text = {
3840
3941 // Converts JSON strings to/from your types
4042 // and asserts the results of JSON.parse at runtime
41-function toTopLevel(json: string): TopLevel[] {
42- return cast(JSON.parse(json), a(r("TopLevel")));
43+function toTopLevel(json: string): TopLevelElement[] {
44+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4345 }
4446
45-function topLevelToJson(value: TopLevel[]): string {
46- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
47+function topLevelToJson(value: TopLevelElement[]): string {
48+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4749 }
4850
4951 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -200,7 +202,7 @@ function r(name: string) {
200202 }
201203
202204 const typeMap: any = {
203- "TopLevel": o([
205+ "TopLevelElement": o([
204206 { json: "id", js: "id", typ: "" },
205207 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
206208 { json: "keywords", js: "keywords", typ: a("") },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a("") },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: string[];
@@ -37,12 +39,12 @@ export interface Text {
3739 // Converts JSON strings to/from your types
3840 // and asserts the results of JSON.parse at runtime
3941 export class Convert {
40- public static toTopLevel(json: string): TopLevel[] {
41- return cast(JSON.parse(json), a(r("TopLevel")));
42+ public static toTopLevel(json: string): TopLevelElement[] {
43+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4244 }
4345
44- public static topLevelToJson(value: TopLevel[]): string {
45- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
46+ public static topLevelToJson(value: TopLevelElement[]): string {
47+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4648 }
4749 }
4850
@@ -200,7 +202,7 @@ function r(name: string) {
200202 }
201203
202204 const typeMap: any = {
203- "TopLevel": o([
205+ "TopLevelElement": o([
204206 { json: "id", js: "id", typ: "" },
205207 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
206208 { json: "keywords", js: "keywords", typ: a("") },
Test case

test/inputs/json/misc/0a91a.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 actor: Actor;
1416 created_at: Date;
1517 id: string;
@@ -233,12 +235,12 @@ export type Type =
233235
234236 // Converts JSON strings to/from your types
235237 // and asserts the results of JSON.parse at runtime
236-function toTopLevel(json: string): TopLevel[] {
237- return cast(JSON.parse(json), a(r("TopLevel")));
238+function toTopLevel(json: string): TopLevelElement[] {
239+ return cast(JSON.parse(json), a(r("TopLevelElement")));
238240 }
239241
240-function topLevelToJson(value: TopLevel[]): string {
241- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
242+function topLevelToJson(value: TopLevelElement[]): string {
243+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
242244 }
243245
244246 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -395,7 +397,7 @@ function r(name: string) {
395397 }
396398
397399 const typeMap: any = {
398- "TopLevel": o([
400+ "TopLevelElement": o([
399401 { json: "actor", js: "actor", typ: r("Actor") },
400402 { json: "created_at", js: "created_at", typ: Date },
401403 { json: "id", js: "id", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "actor", js: "actor", typ: r("Actor") },
176176 { json: "created_at", js: "created_at", typ: Date },
177177 { json: "id", js: "id", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 actor: Actor;
1214 created_at: Date;
1315 id: string;
@@ -227,12 +229,12 @@ export type Type = "PushEvent" | "CreateEvent" | "WatchEvent" | "PullRequestEven
227229 // Converts JSON strings to/from your types
228230 // and asserts the results of JSON.parse at runtime
229231 export class Convert {
230- public static toTopLevel(json: string): TopLevel[] {
231- return cast(JSON.parse(json), a(r("TopLevel")));
232+ public static toTopLevel(json: string): TopLevelElement[] {
233+ return cast(JSON.parse(json), a(r("TopLevelElement")));
232234 }
233235
234- public static topLevelToJson(value: TopLevel[]): string {
235- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
236+ public static topLevelToJson(value: TopLevelElement[]): string {
237+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
236238 }
237239 }
238240
@@ -390,7 +392,7 @@ function r(name: string) {
390392 }
391393
392394 const typeMap: any = {
393- "TopLevel": o([
395+ "TopLevelElement": o([
394396 { json: "actor", js: "actor", typ: r("Actor") },
395397 { json: "created_at", js: "created_at", typ: Date },
396398 { json: "id", js: "id", typ: "" },
Test case

test/inputs/json/misc/10be4.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -80,12 +82,12 @@ export type Title =
8082
8183 // Converts JSON strings to/from your types
8284 // and asserts the results of JSON.parse at runtime
83-function toTopLevel(json: string): TopLevel[] {
84- return cast(JSON.parse(json), a(r("TopLevel")));
85+function toTopLevel(json: string): TopLevelElement[] {
86+ return cast(JSON.parse(json), a(r("TopLevelElement")));
8587 }
8688
87-function topLevelToJson(value: TopLevel[]): string {
88- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
89+function topLevelToJson(value: TopLevelElement[]): string {
90+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
8991 }
9092
9193 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -242,7 +244,7 @@ function r(name: string) {
242244 }
243245
244246 const typeMap: any = {
245- "TopLevel": o([
247+ "TopLevelElement": o([
246248 { json: "id", js: "id", typ: "" },
247249 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
248250 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text" | "PDF";
5254 // Converts JSON strings to/from your types
5355 // and asserts the results of JSON.parse at runtime
5456 export class Convert {
55- public static toTopLevel(json: string): TopLevel[] {
56- return cast(JSON.parse(json), a(r("TopLevel")));
57+ public static toTopLevel(json: string): TopLevelElement[] {
58+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5759 }
5860
59- public static topLevelToJson(value: TopLevel[]): string {
60- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
61+ public static topLevelToJson(value: TopLevelElement[]): string {
62+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6163 }
6264 }
6365
@@ -215,7 +217,7 @@ function r(name: string) {
215217 }
216218
217219 const typeMap: any = {
218- "TopLevel": o([
220+ "TopLevelElement": o([
219221 { json: "id", js: "id", typ: "" },
220222 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
221223 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/13d8d.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 category: string;
1416 context: string;
1517 id: number;
@@ -39,12 +41,12 @@ export type OutcomeStatus = {
3941
4042 // Converts JSON strings to/from your types
4143 // and asserts the results of JSON.parse at runtime
42-function toTopLevel(json: string): TopLevel[] {
43- return cast(JSON.parse(json), a(r("TopLevel")));
44+function toTopLevel(json: string): TopLevelElement[] {
45+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4446 }
4547
46-function topLevelToJson(value: TopLevel[]): string {
47- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
48+function topLevelToJson(value: TopLevelElement[]): string {
49+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4850 }
4951
5052 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -201,7 +203,7 @@ function r(name: string) {
201203 }
202204
203205 const typeMap: any = {
204- "TopLevel": o([
206+ "TopLevelElement": o([
205207 { json: "category", js: "category", typ: "" },
206208 { json: "context", js: "context", typ: "" },
207209 { json: "id", js: "id", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "category", js: "category", typ: "" },
176176 { json: "context", js: "context", typ: "" },
177177 { json: "id", js: "id", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 category: string;
1214 context: string;
1315 id: number;
@@ -38,12 +40,12 @@ export interface OutcomeStatus {
3840 // Converts JSON strings to/from your types
3941 // and asserts the results of JSON.parse at runtime
4042 export class Convert {
41- public static toTopLevel(json: string): TopLevel[] {
42- return cast(JSON.parse(json), a(r("TopLevel")));
43+ public static toTopLevel(json: string): TopLevelElement[] {
44+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4345 }
4446
45- public static topLevelToJson(value: TopLevel[]): string {
46- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
47+ public static topLevelToJson(value: TopLevelElement[]): string {
48+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4749 }
4850 }
4951
@@ -201,7 +203,7 @@ function r(name: string) {
201203 }
202204
203205 const typeMap: any = {
204- "TopLevel": o([
206+ "TopLevelElement": o([
205207 { json: "category", js: "category", typ: "" },
206208 { json: "context", js: "context", typ: "" },
207209 { json: "id", js: "id", typ: 0 },
Test case

test/inputs/json/misc/1a7f5.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/2df80.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 adminregion: Adminregion;
1618 capitalCity: string;
1719 id: string;
@@ -77,7 +79,7 @@ export type Value =
7779 | "East Asia & Pacific"
7880 | "North America";
7981
80-export type PurpleTopLevel = {
82+export type FluffyTopLevel = {
8183 page: number;
8284 pages: number;
8385 per_page: string;
@@ -86,12 +88,12 @@ export type PurpleTopLevel = {
8688
8789 // Converts JSON strings to/from your types
8890 // and asserts the results of JSON.parse at runtime
89-function toTopLevel(json: string): TopLevel[] {
90- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
91+function toTopLevel(json: string): TopLevelUnion[] {
92+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
9193 }
9294
93-function topLevelToJson(value: TopLevel[]): string {
94- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
95+function topLevelToJson(value: TopLevelUnion[]): string {
96+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
9597 }
9698
9799 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -248,7 +250,7 @@ function r(name: string) {
248250 }
249251
250252 const typeMap: any = {
251- "TopLevelElement": o([
253+ "PurpleTopLevel": o([
252254 { json: "adminregion", js: "adminregion", typ: r("Adminregion") },
253255 { json: "capitalCity", js: "capitalCity", typ: "" },
254256 { json: "id", js: "id", typ: "" },
@@ -264,7 +266,7 @@ const typeMap: any = {
264266 { json: "id", js: "id", typ: r("ID") },
265267 { json: "value", js: "value", typ: r("Value") },
266268 ], false),
267- "PurpleTopLevel": o([
269+ "FluffyTopLevel": o([
268270 { json: "page", js: "page", typ: 0 },
269271 { json: "pages", js: "pages", typ: 0 },
270272 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "adminregion", js: "adminregion", typ: r("Adminregion") },
176176 { json: "capitalCity", js: "capitalCity", typ: "" },
177177 { json: "id", js: "id", typ: "" },
@@ -187,7 +187,7 @@ const typeMap = {
187187 { json: "id", js: "id", typ: r("ID") },
188188 { json: "value", js: "value", typ: r("Value") },
189189 ], false),
190- "PurpleTopLevel": o([
190+ "FluffyTopLevel": o([
191191 { json: "page", js: "page", typ: 0 },
192192 { json: "pages", js: "pages", typ: 0 },
193193 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 adminregion: Adminregion;
1416 capitalCity: string;
1517 id: string;
@@ -31,7 +33,7 @@ export type ID = "" | "SAS" | "SSA" | "ECA" | "LAC" | "EAP" | "MNA" | "HIC" | "L
3133
3234 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";
3335
34-export interface PurpleTopLevel {
36+export interface FluffyTopLevel {
3537 page: number;
3638 pages: number;
3739 per_page: string;
@@ -41,12 +43,12 @@ export interface PurpleTopLevel {
4143 // Converts JSON strings to/from your types
4244 // and asserts the results of JSON.parse at runtime
4345 export class Convert {
44- public static toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+ public static toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48- public static topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+ public static topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153 }
5254
@@ -204,7 +206,7 @@ function r(name: string) {
204206 }
205207
206208 const typeMap: any = {
207- "TopLevelElement": o([
209+ "PurpleTopLevel": o([
208210 { json: "adminregion", js: "adminregion", typ: r("Adminregion") },
209211 { json: "capitalCity", js: "capitalCity", typ: "" },
210212 { json: "id", js: "id", typ: "" },
@@ -220,7 +222,7 @@ const typeMap: any = {
220222 { json: "id", js: "id", typ: r("ID") },
221223 { json: "value", js: "value", typ: r("Value") },
222224 ], false),
223- "PurpleTopLevel": o([
225+ "FluffyTopLevel": o([
224226 { json: "page", js: "page", typ: 0 },
225227 { json: "pages", js: "pages", typ: 0 },
226228 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/32d5c.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 BirthDate: Date | null;
1416 BirthDateIsProtected: boolean;
1517 GenderTypeID: number;
@@ -22,12 +24,12 @@ export type TopLevel = {
2224
2325 // Converts JSON strings to/from your types
2426 // and asserts the results of JSON.parse at runtime
25-function toTopLevel(json: string): TopLevel[] {
26- return cast(JSON.parse(json), a(r("TopLevel")));
27+function toTopLevel(json: string): TopLevelElement[] {
28+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2729 }
2830
29-function topLevelToJson(value: TopLevel[]): string {
30- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
31+function topLevelToJson(value: TopLevelElement[]): string {
32+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3133 }
3234
3335 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "BirthDate", js: "BirthDate", typ: u(Date, null) },
189191 { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true },
190192 { json: "GenderTypeID", js: "GenderTypeID", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "BirthDate", js: "BirthDate", typ: u(Date, null) },
176176 { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true },
177177 { json: "GenderTypeID", js: "GenderTypeID", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 BirthDate: Date | null;
1214 BirthDateIsProtected: boolean;
1315 GenderTypeID: number;
@@ -21,12 +23,12 @@ export interface TopLevel {
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "BirthDate", js: "BirthDate", typ: u(Date, null) },
189191 { json: "BirthDateIsProtected", js: "BirthDateIsProtected", typ: true },
190192 { json: "GenderTypeID", js: "GenderTypeID", typ: 0 },
Test case

test/inputs/json/misc/3536b.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -48,12 +50,12 @@ export type Text = {
4850
4951 // Converts JSON strings to/from your types
5052 // and asserts the results of JSON.parse at runtime
51-function toTopLevel(json: string): TopLevel[] {
52- return cast(JSON.parse(json), a(r("TopLevel")));
53+function toTopLevel(json: string): TopLevelElement[] {
54+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5355 }
5456
55-function topLevelToJson(value: TopLevel[]): string {
56- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
57+function topLevelToJson(value: TopLevelElement[]): string {
58+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5759 }
5860
5961 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -210,7 +212,7 @@ function r(name: string) {
210212 }
211213
212214 const typeMap: any = {
213- "TopLevel": o([
215+ "TopLevelElement": o([
214216 { json: "id", js: "id", typ: "" },
215217 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
216218 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -41,12 +43,12 @@ export interface Text {
4143 // Converts JSON strings to/from your types
4244 // and asserts the results of JSON.parse at runtime
4345 export class Convert {
44- public static toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(r("TopLevel")));
46+ public static toTopLevel(json: string): TopLevelElement[] {
47+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4648 }
4749
48- public static topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
50+ public static topLevelToJson(value: TopLevelElement[]): string {
51+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5052 }
5153 }
5254
@@ -204,7 +206,7 @@ function r(name: string) {
204206 }
205207
206208 const typeMap: any = {
207- "TopLevel": o([
209+ "TopLevelElement": o([
208210 { json: "id", js: "id", typ: "" },
209211 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
210212 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/43970.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 ID: number;
1416 Name: string;
1517 Notes: string;
@@ -17,12 +19,12 @@ export type TopLevel = {
1719
1820 // Converts JSON strings to/from your types
1921 // and asserts the results of JSON.parse at runtime
20-function toTopLevel(json: string): TopLevel[] {
21- return cast(JSON.parse(json), a(r("TopLevel")));
22+function toTopLevel(json: string): TopLevelElement[] {
23+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2224 }
2325
24-function topLevelToJson(value: TopLevel[]): string {
25- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
26+function topLevelToJson(value: TopLevelElement[]): string {
27+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2628 }
2729
2830 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "ID", js: "ID", typ: 0 },
184186 { json: "Name", js: "Name", typ: "" },
185187 { json: "Notes", js: "Notes", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "ID", js: "ID", typ: 0 },
176176 { json: "Name", js: "Name", typ: "" },
177177 { json: "Notes", js: "Notes", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 ID: number;
1214 Name: string;
1315 Notes: string;
@@ -16,12 +18,12 @@ export interface TopLevel {
1618 // Converts JSON strings to/from your types
1719 // and asserts the results of JSON.parse at runtime
1820 export class Convert {
19- public static toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+ public static toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23- public static topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+ public static topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628 }
2729
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "ID", js: "ID", typ: 0 },
184186 { json: "Name", js: "Name", typ: "" },
185187 { json: "Notes", js: "Notes", typ: "" },
Test case

test/inputs/json/misc/570ec.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: string[];
@@ -48,12 +50,12 @@ export type Text = {
4850
4951 // Converts JSON strings to/from your types
5052 // and asserts the results of JSON.parse at runtime
51-function toTopLevel(json: string): TopLevel[] {
52- return cast(JSON.parse(json), a(r("TopLevel")));
53+function toTopLevel(json: string): TopLevelElement[] {
54+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5355 }
5456
55-function topLevelToJson(value: TopLevel[]): string {
56- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
57+function topLevelToJson(value: TopLevelElement[]): string {
58+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5759 }
5860
5961 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -210,7 +212,7 @@ function r(name: string) {
210212 }
211213
212214 const typeMap: any = {
213- "TopLevel": o([
215+ "TopLevelElement": o([
214216 { json: "id", js: "id", typ: "" },
215217 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
216218 { json: "keywords", js: "keywords", typ: a("") },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a("") },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: string[];
@@ -44,12 +46,12 @@ export interface Text {
4446 // Converts JSON strings to/from your types
4547 // and asserts the results of JSON.parse at runtime
4648 export class Convert {
47- public static toTopLevel(json: string): TopLevel[] {
48- return cast(JSON.parse(json), a(r("TopLevel")));
49+ public static toTopLevel(json: string): TopLevelElement[] {
50+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4951 }
5052
51- public static topLevelToJson(value: TopLevel[]): string {
52- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
53+ public static topLevelToJson(value: TopLevelElement[]): string {
54+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5355 }
5456 }
5557
@@ -207,7 +209,7 @@ function r(name: string) {
207209 }
208210
209211 const typeMap: any = {
210- "TopLevel": o([
212+ "TopLevelElement": o([
211213 { json: "id", js: "id", typ: "" },
212214 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
213215 { json: "keywords", js: "keywords", typ: a("") },
Test case

test/inputs/json/misc/5eae5.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 Date: Date;
1416 ID: number;
1517 Sponsor: string;
@@ -18,12 +20,12 @@ export type TopLevel = {
1820
1921 // Converts JSON strings to/from your types
2022 // and asserts the results of JSON.parse at runtime
21-function toTopLevel(json: string): TopLevel[] {
22- return cast(JSON.parse(json), a(r("TopLevel")));
23+function toTopLevel(json: string): TopLevelElement[] {
24+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2325 }
2426
25-function topLevelToJson(value: TopLevel[]): string {
26- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
27+function topLevelToJson(value: TopLevelElement[]): string {
28+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2729 }
2830
2931 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -180,7 +182,7 @@ function r(name: string) {
180182 }
181183
182184 const typeMap: any = {
183- "TopLevel": o([
185+ "TopLevelElement": o([
184186 { json: "Date", js: "Date", typ: Date },
185187 { json: "ID", js: "ID", typ: 0 },
186188 { json: "Sponsor", js: "Sponsor", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "Date", js: "Date", typ: Date },
176176 { json: "ID", js: "ID", typ: 0 },
177177 { json: "Sponsor", js: "Sponsor", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 Date: Date;
1214 ID: number;
1315 Sponsor: string;
@@ -17,12 +19,12 @@ export interface TopLevel {
1719 // Converts JSON strings to/from your types
1820 // and asserts the results of JSON.parse at runtime
1921 export class Convert {
20- public static toTopLevel(json: string): TopLevel[] {
21- return cast(JSON.parse(json), a(r("TopLevel")));
22+ public static toTopLevel(json: string): TopLevelElement[] {
23+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2224 }
2325
24- public static topLevelToJson(value: TopLevel[]): string {
25- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
26+ public static topLevelToJson(value: TopLevelElement[]): string {
27+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2628 }
2729 }
2830
@@ -180,7 +182,7 @@ function r(name: string) {
180182 }
181183
182184 const typeMap: any = {
183- "TopLevel": o([
185+ "TopLevelElement": o([
184186 { json: "Date", js: "Date", typ: Date },
185187 { json: "ID", js: "ID", typ: 0 },
186188 { json: "Sponsor", js: "Sponsor", typ: "" },
Test case

test/inputs/json/misc/66121.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -57,12 +59,12 @@ export type Title =
5759
5860 // Converts JSON strings to/from your types
5961 // and asserts the results of JSON.parse at runtime
60-function toTopLevel(json: string): TopLevel[] {
61- return cast(JSON.parse(json), a(r("TopLevel")));
62+function toTopLevel(json: string): TopLevelElement[] {
63+ return cast(JSON.parse(json), a(r("TopLevelElement")));
6264 }
6365
64-function topLevelToJson(value: TopLevel[]): string {
65- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
66+function topLevelToJson(value: TopLevelElement[]): string {
67+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6668 }
6769
6870 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -219,7 +221,7 @@ function r(name: string) {
219221 }
220222
221223 const typeMap: any = {
222- "TopLevel": o([
224+ "TopLevelElement": o([
223225 { json: "id", js: "id", typ: "" },
224226 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
225227 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -47,12 +49,12 @@ export type Title = "HTML";
4749 // Converts JSON strings to/from your types
4850 // and asserts the results of JSON.parse at runtime
4951 export class Convert {
50- public static toTopLevel(json: string): TopLevel[] {
51- return cast(JSON.parse(json), a(r("TopLevel")));
52+ public static toTopLevel(json: string): TopLevelElement[] {
53+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5254 }
5355
54- public static topLevelToJson(value: TopLevel[]): string {
55- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
56+ public static topLevelToJson(value: TopLevelElement[]): string {
57+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5658 }
5759 }
5860
@@ -210,7 +212,7 @@ function r(name: string) {
210212 }
211213
212214 const typeMap: any = {
213- "TopLevel": o([
215+ "TopLevelElement": o([
214216 { json: "id", js: "id", typ: "" },
215217 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
216218 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/6eb00.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 DirectorateID: number;
1416 Id: number;
1517 Name: string;
@@ -17,12 +19,12 @@ export type TopLevel = {
1719
1820 // Converts JSON strings to/from your types
1921 // and asserts the results of JSON.parse at runtime
20-function toTopLevel(json: string): TopLevel[] {
21- return cast(JSON.parse(json), a(r("TopLevel")));
22+function toTopLevel(json: string): TopLevelElement[] {
23+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2224 }
2325
24-function topLevelToJson(value: TopLevel[]): string {
25- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
26+function topLevelToJson(value: TopLevelElement[]): string {
27+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2628 }
2729
2830 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "DirectorateID", js: "DirectorateID", typ: 0 },
184186 { json: "Id", js: "Id", typ: 0 },
185187 { json: "Name", js: "Name", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "DirectorateID", js: "DirectorateID", typ: 0 },
176176 { json: "Id", js: "Id", typ: 0 },
177177 { json: "Name", js: "Name", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 DirectorateID: number;
1214 Id: number;
1315 Name: string;
@@ -16,12 +18,12 @@ export interface TopLevel {
1618 // Converts JSON strings to/from your types
1719 // and asserts the results of JSON.parse at runtime
1820 export class Convert {
19- public static toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+ public static toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23- public static topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+ public static topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628 }
2729
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "DirectorateID", js: "DirectorateID", typ: 0 },
184186 { json: "Id", js: "Id", typ: 0 },
185187 { json: "Name", js: "Name", typ: "" },
Test case

test/inputs/json/misc/77392.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 designation: string;
1416 discovery_date: Date;
1517 h_mag?: string;
@@ -40,12 +42,12 @@ export type Pha =
4042
4143 // Converts JSON strings to/from your types
4244 // and asserts the results of JSON.parse at runtime
43-function toTopLevel(json: string): TopLevel[] {
44- return cast(JSON.parse(json), a(r("TopLevel")));
45+function toTopLevel(json: string): TopLevelElement[] {
46+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4547 }
4648
47-function topLevelToJson(value: TopLevel[]): string {
48- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
49+function topLevelToJson(value: TopLevelElement[]): string {
50+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4951 }
5052
5153 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -202,7 +204,7 @@ function r(name: string) {
202204 }
203205
204206 const typeMap: any = {
205- "TopLevel": o([
207+ "TopLevelElement": o([
206208 { json: "designation", js: "designation", typ: "" },
207209 { json: "discovery_date", js: "discovery_date", typ: Date },
208210 { json: "h_mag", js: "h_mag", typ: u(undefined, "") },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "designation", js: "designation", typ: "" },
176176 { json: "discovery_date", js: "discovery_date", typ: Date },
177177 { json: "h_mag", js: "h_mag", typ: u(undefined, "") },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 designation: string;
1214 discovery_date: Date;
1315 h_mag?: string;
@@ -27,12 +29,12 @@ export type Pha = "Y" | "N" | "n/a";
2729 // Converts JSON strings to/from your types
2830 // and asserts the results of JSON.parse at runtime
2931 export class Convert {
30- public static toTopLevel(json: string): TopLevel[] {
31- return cast(JSON.parse(json), a(r("TopLevel")));
32+ public static toTopLevel(json: string): TopLevelElement[] {
33+ return cast(JSON.parse(json), a(r("TopLevelElement")));
3234 }
3335
34- public static topLevelToJson(value: TopLevel[]): string {
35- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
36+ public static topLevelToJson(value: TopLevelElement[]): string {
37+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3638 }
3739 }
3840
@@ -190,7 +192,7 @@ function r(name: string) {
190192 }
191193
192194 const typeMap: any = {
193- "TopLevel": o([
195+ "TopLevelElement": o([
194196 { json: "designation", js: "designation", typ: "" },
195197 { json: "discovery_date", js: "discovery_date", typ: Date },
196198 { json: "h_mag", js: "h_mag", typ: u(undefined, "") },
Test case

test/inputs/json/misc/7f568.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 comments: number;
1416 comments_url: string;
1517 commits_url: string;
@@ -44,12 +46,12 @@ export type Type =
4446
4547 // Converts JSON strings to/from your types
4648 // and asserts the results of JSON.parse at runtime
47-function toTopLevel(json: string): TopLevel[] {
48- return cast(JSON.parse(json), a(r("TopLevel")));
49+function toTopLevel(json: string): TopLevelElement[] {
50+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4951 }
5052
51-function topLevelToJson(value: TopLevel[]): string {
52- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
53+function topLevelToJson(value: TopLevelElement[]): string {
54+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5355 }
5456
5557 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -206,7 +208,7 @@ function r(name: string) {
206208 }
207209
208210 const typeMap: any = {
209- "TopLevel": o([
211+ "TopLevelElement": o([
210212 { json: "comments", js: "comments", typ: 0 },
211213 { json: "comments_url", js: "comments_url", typ: "" },
212214 { json: "commits_url", js: "commits_url", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "comments", js: "comments", typ: 0 },
176176 { json: "comments_url", js: "comments_url", typ: "" },
177177 { json: "commits_url", js: "commits_url", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 comments: number;
1214 comments_url: string;
1315 commits_url: string;
@@ -41,12 +43,12 @@ export type Type = "text/plain";
4143 // Converts JSON strings to/from your types
4244 // and asserts the results of JSON.parse at runtime
4345 export class Convert {
44- public static toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(r("TopLevel")));
46+ public static toTopLevel(json: string): TopLevelElement[] {
47+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4648 }
4749
48- public static topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
50+ public static topLevelToJson(value: TopLevelElement[]): string {
51+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5052 }
5153 }
5254
@@ -204,7 +206,7 @@ function r(name: string) {
204206 }
205207
206208 const typeMap: any = {
207- "TopLevel": o([
209+ "TopLevelElement": o([
208210 { json: "comments", js: "comments", typ: 0 },
209211 { json: "comments_url", js: "comments_url", typ: "" },
210212 { json: "commits_url", js: "commits_url", typ: "" },
Test case

test/inputs/json/misc/7fbfb.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 country: Country;
1618 date: string;
1719 decimal: string;
@@ -32,7 +34,7 @@ export type Value =
3234 "China"
3335 | "GDP (current US$)";
3436
35-export type PurpleTopLevel = {
37+export type FluffyTopLevel = {
3638 page: number;
3739 pages: number;
3840 per_page: string;
@@ -41,12 +43,12 @@ export type PurpleTopLevel = {
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+function toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+function topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevelElement": o([
208+ "PurpleTopLevel": o([
207209 { json: "country", js: "country", typ: r("Country") },
208210 { json: "date", js: "date", typ: "" },
209211 { json: "decimal", js: "decimal", typ: "" },
@@ -214,7 +216,7 @@ const typeMap: any = {
214216 { json: "id", js: "id", typ: r("ID") },
215217 { json: "value", js: "value", typ: r("Value") },
216218 ], false),
217- "PurpleTopLevel": o([
219+ "FluffyTopLevel": o([
218220 { json: "page", js: "page", typ: 0 },
219221 { json: "pages", js: "pages", typ: 0 },
220222 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "country", js: "country", typ: r("Country") },
176176 { json: "date", js: "date", typ: "" },
177177 { json: "decimal", js: "decimal", typ: "" },
@@ -182,7 +182,7 @@ const typeMap = {
182182 { json: "id", js: "id", typ: r("ID") },
183183 { json: "value", js: "value", typ: r("Value") },
184184 ], false),
185- "PurpleTopLevel": o([
185+ "FluffyTopLevel": o([
186186 { json: "page", js: "page", typ: 0 },
187187 { json: "pages", js: "pages", typ: 0 },
188188 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 country: Country;
1416 date: string;
1517 decimal: string;
@@ -26,7 +28,7 @@ export type ID = "CN" | "NY.GDP.MKTP.CD";
2628
2729 export type Value = "China" | "GDP (current US$)";
2830
29-export interface PurpleTopLevel {
31+export interface FluffyTopLevel {
3032 page: number;
3133 pages: number;
3234 per_page: string;
@@ -36,12 +38,12 @@ export interface PurpleTopLevel {
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
41+ public static toTopLevel(json: string): TopLevelUnion[] {
42+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
45+ public static topLevelToJson(value: TopLevelUnion[]): string {
46+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevelElement": o([
204+ "PurpleTopLevel": o([
203205 { json: "country", js: "country", typ: r("Country") },
204206 { json: "date", js: "date", typ: "" },
205207 { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
210212 { json: "id", js: "id", typ: r("ID") },
211213 { json: "value", js: "value", typ: r("Value") },
212214 ], false),
213- "PurpleTopLevel": o([
215+ "FluffyTopLevel": o([
214216 { json: "page", js: "page", typ: 0 },
215217 { json: "pages", js: "pages", typ: 0 },
216218 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/9847b.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,19 +9,21 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 name: string;
1517 };
1618
1719 // Converts JSON strings to/from your types
1820 // and asserts the results of JSON.parse at runtime
19-function toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+function toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23-function topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+function topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628
2729 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "id", js: "id", typ: "" },
183185 { json: "name", js: "name", typ: "" },
184186 ], false),
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "name", js: "name", typ: "" },
177177 ], false),
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 name: string;
1315 }
@@ -15,12 +17,12 @@ export interface TopLevel {
1517 // Converts JSON strings to/from your types
1618 // and asserts the results of JSON.parse at runtime
1719 export class Convert {
18- public static toTopLevel(json: string): TopLevel[] {
19- return cast(JSON.parse(json), a(r("TopLevel")));
20+ public static toTopLevel(json: string): TopLevelElement[] {
21+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2022 }
2123
22- public static topLevelToJson(value: TopLevel[]): string {
23- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
24+ public static topLevelToJson(value: TopLevelElement[]): string {
25+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2426 }
2527 }
2628
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "id", js: "id", typ: "" },
183185 { json: "name", js: "name", typ: "" },
184186 ], false),
Test case

test/inputs/json/misc/996bd.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -57,12 +59,12 @@ export type Title =
5759
5860 // Converts JSON strings to/from your types
5961 // and asserts the results of JSON.parse at runtime
60-function toTopLevel(json: string): TopLevel[] {
61- return cast(JSON.parse(json), a(r("TopLevel")));
62+function toTopLevel(json: string): TopLevelElement[] {
63+ return cast(JSON.parse(json), a(r("TopLevelElement")));
6264 }
6365
64-function topLevelToJson(value: TopLevel[]): string {
65- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
66+function topLevelToJson(value: TopLevelElement[]): string {
67+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6668 }
6769
6870 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -219,7 +221,7 @@ function r(name: string) {
219221 }
220222
221223 const typeMap: any = {
222- "TopLevel": o([
224+ "TopLevelElement": o([
223225 { json: "id", js: "id", typ: "" },
224226 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
225227 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -45,12 +47,12 @@ export type Title = "Plain Text" | "HTML";
4547 // Converts JSON strings to/from your types
4648 // and asserts the results of JSON.parse at runtime
4749 export class Convert {
48- public static toTopLevel(json: string): TopLevel[] {
49- return cast(JSON.parse(json), a(r("TopLevel")));
50+ public static toTopLevel(json: string): TopLevelElement[] {
51+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5052 }
5153
52- public static topLevelToJson(value: TopLevel[]): string {
53- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
54+ public static topLevelToJson(value: TopLevelElement[]): string {
55+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5456 }
5557 }
5658
@@ -208,7 +210,7 @@ function r(name: string) {
208210 }
209211
210212 const typeMap: any = {
211- "TopLevel": o([
213+ "TopLevelElement": o([
212214 { json: "id", js: "id", typ: "" },
213215 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
214216 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/9a503.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -43,12 +45,12 @@ export type Text = {
4345
4446 // Converts JSON strings to/from your types
4547 // and asserts the results of JSON.parse at runtime
46-function toTopLevel(json: string): TopLevel[] {
47- return cast(JSON.parse(json), a(r("TopLevel")));
48+function toTopLevel(json: string): TopLevelElement[] {
49+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4850 }
4951
50-function topLevelToJson(value: TopLevel[]): string {
51- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
52+function topLevelToJson(value: TopLevelElement[]): string {
53+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5254 }
5355
5456 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -205,7 +207,7 @@ function r(name: string) {
205207 }
206208
207209 const typeMap: any = {
208- "TopLevel": o([
210+ "TopLevelElement": o([
209211 { json: "id", js: "id", typ: "" },
210212 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
211213 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -39,12 +41,12 @@ export interface Text {
3941 // Converts JSON strings to/from your types
4042 // and asserts the results of JSON.parse at runtime
4143 export class Convert {
42- public static toTopLevel(json: string): TopLevel[] {
43- return cast(JSON.parse(json), a(r("TopLevel")));
44+ public static toTopLevel(json: string): TopLevelElement[] {
45+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4446 }
4547
46- public static topLevelToJson(value: TopLevel[]): string {
47- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
48+ public static topLevelToJson(value: TopLevelElement[]): string {
49+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4850 }
4951 }
5052
@@ -202,7 +204,7 @@ function r(name: string) {
202204 }
203205
204206 const typeMap: any = {
205- "TopLevel": o([
207+ "TopLevelElement": o([
206208 { json: "id", js: "id", typ: "" },
207209 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
208210 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/9eed5.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -42,12 +44,12 @@ export type Text = {
4244
4345 // Converts JSON strings to/from your types
4446 // and asserts the results of JSON.parse at runtime
45-function toTopLevel(json: string): TopLevel[] {
46- return cast(JSON.parse(json), a(r("TopLevel")));
47+function toTopLevel(json: string): TopLevelElement[] {
48+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4749 }
4850
49-function topLevelToJson(value: TopLevel[]): string {
50- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
51+function topLevelToJson(value: TopLevelElement[]): string {
52+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5153 }
5254
5355 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -204,7 +206,7 @@ function r(name: string) {
204206 }
205207
206208 const typeMap: any = {
207- "TopLevel": o([
209+ "TopLevelElement": o([
208210 { json: "id", js: "id", typ: "" },
209211 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
210212 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -39,12 +41,12 @@ export interface Text {
3941 // Converts JSON strings to/from your types
4042 // and asserts the results of JSON.parse at runtime
4143 export class Convert {
42- public static toTopLevel(json: string): TopLevel[] {
43- return cast(JSON.parse(json), a(r("TopLevel")));
44+ public static toTopLevel(json: string): TopLevelElement[] {
45+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4446 }
4547
46- public static topLevelToJson(value: TopLevel[]): string {
47- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
48+ public static topLevelToJson(value: TopLevelElement[]): string {
49+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4850 }
4951 }
5052
@@ -202,7 +204,7 @@ function r(name: string) {
202204 }
203205
204206 const typeMap: any = {
205- "TopLevel": o([
207+ "TopLevelElement": o([
206208 { json: "id", js: "id", typ: "" },
207209 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
208210 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/a45b0.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/ab0d1.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/ad8be.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 identifiers: Identifier[];
1517 keywords: Keyword[];
@@ -80,12 +82,12 @@ export type Title =
8082
8183 // Converts JSON strings to/from your types
8284 // and asserts the results of JSON.parse at runtime
83-function toTopLevel(json: string): TopLevel[] {
84- return cast(JSON.parse(json), a(r("TopLevel")));
85+function toTopLevel(json: string): TopLevelElement[] {
86+ return cast(JSON.parse(json), a(r("TopLevelElement")));
8587 }
8688
87-function topLevelToJson(value: TopLevel[]): string {
88- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
89+function topLevelToJson(value: TopLevelElement[]): string {
90+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
8991 }
9092
9193 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -242,7 +244,7 @@ function r(name: string) {
242244 }
243245
244246 const typeMap: any = {
245- "TopLevel": o([
247+ "TopLevelElement": o([
246248 { json: "id", js: "id", typ: "" },
247249 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
248250 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
177177 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 identifiers: Identifier[];
1315 keywords: Keyword[];
@@ -52,12 +54,12 @@ export type Title = "HTML" | "Plain Text" | "PDF";
5254 // Converts JSON strings to/from your types
5355 // and asserts the results of JSON.parse at runtime
5456 export class Convert {
55- public static toTopLevel(json: string): TopLevel[] {
56- return cast(JSON.parse(json), a(r("TopLevel")));
57+ public static toTopLevel(json: string): TopLevelElement[] {
58+ return cast(JSON.parse(json), a(r("TopLevelElement")));
5759 }
5860
59- public static topLevelToJson(value: TopLevel[]): string {
60- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
61+ public static topLevelToJson(value: TopLevelElement[]): string {
62+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
6163 }
6264 }
6365
@@ -215,7 +217,7 @@ function r(name: string) {
215217 }
216218
217219 const typeMap: any = {
218- "TopLevel": o([
220+ "TopLevelElement": o([
219221 { json: "id", js: "id", typ: "" },
220222 { json: "identifiers", js: "identifiers", typ: a(r("Identifier")) },
221223 { json: "keywords", js: "keywords", typ: a(r("Keyword")) },
Test case

test/inputs/json/misc/b4865.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 ":@computed_region_cbhk_fwbd"?: string;
1416 ":@computed_region_nnqa_25f4"?: string;
1517 fall: Fall;
@@ -41,12 +43,12 @@ export type Nametype =
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(r("TopLevel")));
46+function toTopLevel(json: string): TopLevelElement[] {
47+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
50+function topLevelToJson(value: TopLevelElement[]): string {
51+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevel": o([
208+ "TopLevelElement": o([
207209 { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") },
208210 { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") },
209211 { json: "fall", js: "fall", typ: r("Fall") },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") },
176176 { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") },
177177 { json: "fall", js: "fall", typ: r("Fall") },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 ":@computed_region_cbhk_fwbd"?: string;
1214 ":@computed_region_nnqa_25f4"?: string;
1315 fall: Fall;
@@ -36,12 +38,12 @@ export type Nametype = "Valid";
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(r("TopLevel")));
41+ public static toTopLevel(json: string): TopLevelElement[] {
42+ return cast(JSON.parse(json), a(r("TopLevelElement")));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
45+ public static topLevelToJson(value: TopLevelElement[]): string {
46+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevel": o([
204+ "TopLevelElement": o([
203205 { json: ":@computed_region_cbhk_fwbd", js: ":@computed_region_cbhk_fwbd", typ: u(undefined, "") },
204206 { json: ":@computed_region_nnqa_25f4", js: ":@computed_region_nnqa_25f4", typ: u(undefined, "") },
205207 { json: "fall", js: "fall", typ: r("Fall") },
Test case

test/inputs/json/misc/c8c7e.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 country: Country;
1618 date: string;
1719 decimal: string;
@@ -32,7 +34,7 @@ export type Value =
3234 "India"
3335 | "GDP (current US$)";
3436
35-export type PurpleTopLevel = {
37+export type FluffyTopLevel = {
3638 page: number;
3739 pages: number;
3840 per_page: string;
@@ -41,12 +43,12 @@ export type PurpleTopLevel = {
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+function toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+function topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevelElement": o([
208+ "PurpleTopLevel": o([
207209 { json: "country", js: "country", typ: r("Country") },
208210 { json: "date", js: "date", typ: "" },
209211 { json: "decimal", js: "decimal", typ: "" },
@@ -214,7 +216,7 @@ const typeMap: any = {
214216 { json: "id", js: "id", typ: r("ID") },
215217 { json: "value", js: "value", typ: r("Value") },
216218 ], false),
217- "PurpleTopLevel": o([
219+ "FluffyTopLevel": o([
218220 { json: "page", js: "page", typ: 0 },
219221 { json: "pages", js: "pages", typ: 0 },
220222 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "country", js: "country", typ: r("Country") },
176176 { json: "date", js: "date", typ: "" },
177177 { json: "decimal", js: "decimal", typ: "" },
@@ -182,7 +182,7 @@ const typeMap = {
182182 { json: "id", js: "id", typ: r("ID") },
183183 { json: "value", js: "value", typ: r("Value") },
184184 ], false),
185- "PurpleTopLevel": o([
185+ "FluffyTopLevel": o([
186186 { json: "page", js: "page", typ: 0 },
187187 { json: "pages", js: "pages", typ: 0 },
188188 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 country: Country;
1416 date: string;
1517 decimal: string;
@@ -26,7 +28,7 @@ export type ID = "IN" | "NY.GDP.MKTP.CD";
2628
2729 export type Value = "India" | "GDP (current US$)";
2830
29-export interface PurpleTopLevel {
31+export interface FluffyTopLevel {
3032 page: number;
3133 pages: number;
3234 per_page: string;
@@ -36,12 +38,12 @@ export interface PurpleTopLevel {
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
41+ public static toTopLevel(json: string): TopLevelUnion[] {
42+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
45+ public static topLevelToJson(value: TopLevelUnion[]): string {
46+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevelElement": o([
204+ "PurpleTopLevel": o([
203205 { json: "country", js: "country", typ: r("Country") },
204206 { json: "date", js: "date", typ: "" },
205207 { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
210212 { json: "id", js: "id", typ: r("ID") },
211213 { json: "value", js: "value", typ: r("Value") },
212214 ], false),
213- "PurpleTopLevel": o([
215+ "FluffyTopLevel": o([
214216 { json: "page", js: "page", typ: 0 },
215217 { json: "pages", js: "pages", typ: 0 },
216218 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/cda6c.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 country: Country;
1618 date: string;
1719 decimal: string;
@@ -32,7 +34,7 @@ export type Value =
3234 "China"
3335 | "Population, total";
3436
35-export type PurpleTopLevel = {
37+export type FluffyTopLevel = {
3638 page: number;
3739 pages: number;
3840 per_page: string;
@@ -41,12 +43,12 @@ export type PurpleTopLevel = {
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+function toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+function topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevelElement": o([
208+ "PurpleTopLevel": o([
207209 { json: "country", js: "country", typ: r("Country") },
208210 { json: "date", js: "date", typ: "" },
209211 { json: "decimal", js: "decimal", typ: "" },
@@ -214,7 +216,7 @@ const typeMap: any = {
214216 { json: "id", js: "id", typ: r("ID") },
215217 { json: "value", js: "value", typ: r("Value") },
216218 ], false),
217- "PurpleTopLevel": o([
219+ "FluffyTopLevel": o([
218220 { json: "page", js: "page", typ: 0 },
219221 { json: "pages", js: "pages", typ: 0 },
220222 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "country", js: "country", typ: r("Country") },
176176 { json: "date", js: "date", typ: "" },
177177 { json: "decimal", js: "decimal", typ: "" },
@@ -182,7 +182,7 @@ const typeMap = {
182182 { json: "id", js: "id", typ: r("ID") },
183183 { json: "value", js: "value", typ: r("Value") },
184184 ], false),
185- "PurpleTopLevel": o([
185+ "FluffyTopLevel": o([
186186 { json: "page", js: "page", typ: 0 },
187187 { json: "pages", js: "pages", typ: 0 },
188188 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 country: Country;
1416 date: string;
1517 decimal: string;
@@ -26,7 +28,7 @@ export type ID = "CN" | "SP.POP.TOTL";
2628
2729 export type Value = "China" | "Population, total";
2830
29-export interface PurpleTopLevel {
31+export interface FluffyTopLevel {
3032 page: number;
3133 pages: number;
3234 per_page: string;
@@ -36,12 +38,12 @@ export interface PurpleTopLevel {
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
41+ public static toTopLevel(json: string): TopLevelUnion[] {
42+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
45+ public static topLevelToJson(value: TopLevelUnion[]): string {
46+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevelElement": o([
204+ "PurpleTopLevel": o([
203205 { json: "country", js: "country", typ: r("Country") },
204206 { json: "date", js: "date", typ: "" },
205207 { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
210212 { json: "id", js: "id", typ: r("ID") },
211213 { json: "value", js: "value", typ: r("Value") },
212214 ], false),
213- "PurpleTopLevel": o([
215+ "FluffyTopLevel": o([
214216 { json: "page", js: "page", typ: 0 },
215217 { json: "pages", js: "pages", typ: 0 },
216218 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/e2a58.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,19 +9,21 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 date: string;
1416 "stop-and-search": string[];
1517 };
1618
1719 // Converts JSON strings to/from your types
1820 // and asserts the results of JSON.parse at runtime
19-function toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+function toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23-function topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+function topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628
2729 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "date", js: "date", typ: "" },
183185 { json: "stop-and-search", js: "stop-and-search", typ: a("") },
184186 ], false),
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "date", js: "date", typ: "" },
176176 { json: "stop-and-search", js: "stop-and-search", typ: a("") },
177177 ], false),
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 date: string;
1214 "stop-and-search": string[];
1315 }
@@ -15,12 +17,12 @@ export interface TopLevel {
1517 // Converts JSON strings to/from your types
1618 // and asserts the results of JSON.parse at runtime
1719 export class Convert {
18- public static toTopLevel(json: string): TopLevel[] {
19- return cast(JSON.parse(json), a(r("TopLevel")));
20+ public static toTopLevel(json: string): TopLevelElement[] {
21+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2022 }
2123
22- public static topLevelToJson(value: TopLevel[]): string {
23- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
24+ public static topLevelToJson(value: TopLevelElement[]): string {
25+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2426 }
2527 }
2628
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "date", js: "date", typ: "" },
183185 { json: "stop-and-search", js: "stop-and-search", typ: a("") },
184186 ], false),
Test case

test/inputs/json/misc/e53b5.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
15+
16+export type PurpleTopLevel = {
1517 country: Country;
1618 date: string;
1719 decimal: string;
@@ -32,7 +34,7 @@ export type Value =
3234 "India"
3335 | "Population, total";
3436
35-export type PurpleTopLevel = {
37+export type FluffyTopLevel = {
3638 page: number;
3739 pages: number;
3840 per_page: string;
@@ -41,12 +43,12 @@ export type PurpleTopLevel = {
4143
4244 // Converts JSON strings to/from your types
4345 // and asserts the results of JSON.parse at runtime
44-function toTopLevel(json: string): TopLevel[] {
45- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
46+function toTopLevel(json: string): TopLevelUnion[] {
47+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4648 }
4749
48-function topLevelToJson(value: TopLevel[]): string {
49- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
50+function topLevelToJson(value: TopLevelUnion[]): string {
51+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
5052 }
5153
5254 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -203,7 +205,7 @@ function r(name: string) {
203205 }
204206
205207 const typeMap: any = {
206- "TopLevelElement": o([
208+ "PurpleTopLevel": o([
207209 { json: "country", js: "country", typ: r("Country") },
208210 { json: "date", js: "date", typ: "" },
209211 { json: "decimal", js: "decimal", typ: "" },
@@ -214,7 +216,7 @@ const typeMap: any = {
214216 { json: "id", js: "id", typ: r("ID") },
215217 { json: "value", js: "value", typ: r("Value") },
216218 ], false),
217- "PurpleTopLevel": o([
219+ "FluffyTopLevel": o([
218220 { json: "page", js: "page", typ: 0 },
219221 { json: "pages", js: "pages", typ: 0 },
220222 { json: "per_page", js: "per_page", typ: "" },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "country", js: "country", typ: r("Country") },
176176 { json: "date", js: "date", typ: "" },
177177 { json: "decimal", js: "decimal", typ: "" },
@@ -182,7 +182,7 @@ const typeMap = {
182182 { json: "id", js: "id", typ: r("ID") },
183183 { json: "value", js: "value", typ: r("Value") },
184184 ], false),
185- "PurpleTopLevel": o([
185+ "FluffyTopLevel": o([
186186 { json: "page", js: "page", typ: 0 },
187187 { json: "pages", js: "pages", typ: 0 },
188188 { json: "per_page", js: "per_page", typ: "" },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel;
13+
14+export interface PurpleTopLevel {
1315 country: Country;
1416 date: string;
1517 decimal: string;
@@ -26,7 +28,7 @@ export type ID = "IN" | "SP.POP.TOTL";
2628
2729 export type Value = "India" | "Population, total";
2830
29-export interface PurpleTopLevel {
31+export interface FluffyTopLevel {
3032 page: number;
3133 pages: number;
3234 per_page: string;
@@ -36,12 +38,12 @@ export interface PurpleTopLevel {
3638 // Converts JSON strings to/from your types
3739 // and asserts the results of JSON.parse at runtime
3840 export class Convert {
39- public static toTopLevel(json: string): TopLevel[] {
40- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"))));
41+ public static toTopLevel(json: string): TopLevelUnion[] {
42+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"))));
4143 }
4244
43- public static topLevelToJson(value: TopLevel[]): string {
44- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel")))), null, 2);
45+ public static topLevelToJson(value: TopLevelUnion[]): string {
46+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel")))), null, 2);
4547 }
4648 }
4749
@@ -199,7 +201,7 @@ function r(name: string) {
199201 }
200202
201203 const typeMap: any = {
202- "TopLevelElement": o([
204+ "PurpleTopLevel": o([
203205 { json: "country", js: "country", typ: r("Country") },
204206 { json: "date", js: "date", typ: "" },
205207 { json: "decimal", js: "decimal", typ: "" },
@@ -210,7 +212,7 @@ const typeMap: any = {
210212 { json: "id", js: "id", typ: r("ID") },
211213 { json: "value", js: "value", typ: r("Value") },
212214 ], false),
213- "PurpleTopLevel": o([
215+ "FluffyTopLevel": o([
214216 { json: "page", js: "page", typ: 0 },
215217 { json: "pages", js: "pages", typ: 0 },
216218 { json: "per_page", js: "per_page", typ: "" },
Test case

test/inputs/json/misc/e8a0b.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/e8b04.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 averageRating: number;
1416 category?: string;
1517 createdAt: number;
@@ -283,12 +285,12 @@ export type ViewType =
283285
284286 // Converts JSON strings to/from your types
285287 // and asserts the results of JSON.parse at runtime
286-function toTopLevel(json: string): TopLevel[] {
287- return cast(JSON.parse(json), a(r("TopLevel")));
288+function toTopLevel(json: string): TopLevelElement[] {
289+ return cast(JSON.parse(json), a(r("TopLevelElement")));
288290 }
289291
290-function topLevelToJson(value: TopLevel[]): string {
291- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
292+function topLevelToJson(value: TopLevelElement[]): string {
293+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
292294 }
293295
294296 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -445,7 +447,7 @@ function r(name: string) {
445447 }
446448
447449 const typeMap: any = {
448- "TopLevel": o([
450+ "TopLevelElement": o([
449451 { json: "averageRating", js: "averageRating", typ: 0 },
450452 { json: "category", js: "category", typ: u(undefined, "") },
451453 { json: "createdAt", js: "createdAt", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "averageRating", js: "averageRating", typ: 0 },
176176 { json: "category", js: "category", typ: u(undefined, "") },
177177 { json: "createdAt", js: "createdAt", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 averageRating: number;
1214 category?: string;
1315 createdAt: number;
@@ -243,12 +245,12 @@ export type ViewType = "tabular";
243245 // Converts JSON strings to/from your types
244246 // and asserts the results of JSON.parse at runtime
245247 export class Convert {
246- public static toTopLevel(json: string): TopLevel[] {
247- return cast(JSON.parse(json), a(r("TopLevel")));
248+ public static toTopLevel(json: string): TopLevelElement[] {
249+ return cast(JSON.parse(json), a(r("TopLevelElement")));
248250 }
249251
250- public static topLevelToJson(value: TopLevel[]): string {
251- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
252+ public static topLevelToJson(value: TopLevelElement[]): string {
253+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
252254 }
253255 }
254256
@@ -406,7 +408,7 @@ function r(name: string) {
406408 }
407409
408410 const typeMap: any = {
409- "TopLevel": o([
411+ "TopLevelElement": o([
410412 { json: "averageRating", js: "averageRating", typ: 0 },
411413 { json: "category", js: "category", typ: u(undefined, "") },
412414 { json: "createdAt", js: "createdAt", typ: 0 },
Test case

test/inputs/json/misc/f3139.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,19 +9,21 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 id: string;
1416 name: string;
1517 };
1618
1719 // Converts JSON strings to/from your types
1820 // and asserts the results of JSON.parse at runtime
19-function toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+function toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23-function topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+function topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628
2729 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "id", js: "id", typ: "" },
183185 { json: "name", js: "name", typ: "" },
184186 ], false),
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "id", js: "id", typ: "" },
176176 { json: "name", js: "name", typ: "" },
177177 ], false),
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 id: string;
1214 name: string;
1315 }
@@ -15,12 +17,12 @@ export interface TopLevel {
1517 // Converts JSON strings to/from your types
1618 // and asserts the results of JSON.parse at runtime
1719 export class Convert {
18- public static toTopLevel(json: string): TopLevel[] {
19- return cast(JSON.parse(json), a(r("TopLevel")));
20+ public static toTopLevel(json: string): TopLevelElement[] {
21+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2022 }
2123
22- public static topLevelToJson(value: TopLevel[]): string {
23- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
24+ public static topLevelToJson(value: TopLevelElement[]): string {
25+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2426 }
2527 }
2628
@@ -178,7 +180,7 @@ function r(name: string) {
178180 }
179181
180182 const typeMap: any = {
181- "TopLevel": o([
183+ "TopLevelElement": o([
182184 { json: "id", js: "id", typ: "" },
183185 { json: "name", js: "name", typ: "" },
184186 ], false),
Test case

test/inputs/json/misc/f3edf.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/misc/f466a.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 age: number;
1416 country: Country;
1517 females: number;
@@ -23,12 +25,12 @@ export type Country =
2325
2426 // Converts JSON strings to/from your types
2527 // and asserts the results of JSON.parse at runtime
26-function toTopLevel(json: string): TopLevel[] {
27- return cast(JSON.parse(json), a(r("TopLevel")));
28+function toTopLevel(json: string): TopLevelElement[] {
29+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2830 }
2931
30-function topLevelToJson(value: TopLevel[]): string {
31- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
32+function topLevelToJson(value: TopLevelElement[]): string {
33+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3234 }
3335
3436 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -185,7 +187,7 @@ function r(name: string) {
185187 }
186188
187189 const typeMap: any = {
188- "TopLevel": o([
190+ "TopLevelElement": o([
189191 { json: "age", js: "age", typ: 0 },
190192 { json: "country", js: "country", typ: r("Country") },
191193 { json: "females", js: "females", typ: 0 },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "age", js: "age", typ: 0 },
176176 { json: "country", js: "country", typ: r("Country") },
177177 { json: "females", js: "females", typ: 0 },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 age: number;
1214 country: Country;
1315 females: number;
@@ -21,12 +23,12 @@ export type Country = "United States";
2123 // Converts JSON strings to/from your types
2224 // and asserts the results of JSON.parse at runtime
2325 export class Convert {
24- public static toTopLevel(json: string): TopLevel[] {
25- return cast(JSON.parse(json), a(r("TopLevel")));
26+ public static toTopLevel(json: string): TopLevelElement[] {
27+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2628 }
2729
28- public static topLevelToJson(value: TopLevel[]): string {
29- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
30+ public static topLevelToJson(value: TopLevelElement[]): string {
31+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
3032 }
3133 }
3234
@@ -184,7 +186,7 @@ function r(name: string) {
184186 }
185187
186188 const typeMap: any = {
187- "TopLevel": o([
189+ "TopLevelElement": o([
188190 { json: "age", js: "age", typ: 0 },
189191 { json: "country", js: "country", typ: r("Country") },
190192 { json: "females", js: "females", typ: 0 },
Test case

test/inputs/json/priority/bug863.json

3 generated files · +26 −22
Mflowdefault / TopLevel.js+11 −9
@@ -9,9 +9,11 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = TopLevelElement[] | PurpleTopLevel | string;
12+export type TopLevel = TopLevelUnion[];
1313
14-export type TopLevelElement = {
14+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel | string;
15+
16+export type PurpleTopLevel = {
1517 ALIENLEVEL: number;
1618 BREED: Breed;
1719 CHAR_DIMENSION: number;
@@ -59,7 +61,7 @@ export type Sex =
5961 | "Male"
6062 | "Female";
6163
62-export type PurpleTopLevel = {
64+export type FluffyTopLevel = {
6365 ADVENTURERCOUNT: number;
6466 AGENTCOUNT: number;
6567 ATROXCOUNT: number;
@@ -99,12 +101,12 @@ export type PurpleTopLevel = {
99101
100102 // Converts JSON strings to/from your types
101103 // and asserts the results of JSON.parse at runtime
102-function toTopLevel(json: string): TopLevel[] {
103- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), "")));
104+function toTopLevel(json: string): TopLevelUnion[] {
105+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), "")));
104106 }
105107
106-function topLevelToJson(value: TopLevel[]): string {
107- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2);
108+function topLevelToJson(value: TopLevelUnion[]): string {
109+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2);
108110 }
109111
110112 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -261,7 +263,7 @@ function r(name: string) {
261263 }
262264
263265 const typeMap: any = {
264- "TopLevelElement": o([
266+ "PurpleTopLevel": o([
265267 { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 },
266268 { json: "BREED", js: "BREED", typ: r("Breed") },
267269 { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 },
@@ -280,7 +282,7 @@ const typeMap: any = {
280282 { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") },
281283 { json: "SEX", js: "SEX", typ: r("Sex") },
282284 ], false),
283- "PurpleTopLevel": o([
285+ "FluffyTopLevel": o([
284286 { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 },
285287 { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 },
286288 { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 },
Mjavascriptdefault / TopLevel.js+4 −4
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), "")));
13+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), "")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2);
17+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevelElement": o([
174+ "PurpleTopLevel": o([
175175 { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 },
176176 { json: "BREED", js: "BREED", typ: r("Breed") },
177177 { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 },
@@ -190,7 +190,7 @@ const typeMap = {
190190 { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") },
191191 { json: "SEX", js: "SEX", typ: r("Sex") },
192192 ], false),
193- "PurpleTopLevel": o([
193+ "FluffyTopLevel": o([
194194 { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 },
195195 { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 },
196196 { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 },
Mtypescriptdefault / TopLevel.ts+11 −9
@@ -7,9 +7,11 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export type TopLevel = TopLevelElement[] | PurpleTopLevel | string;
10+export type TopLevel = TopLevelUnion[];
1111
12-export interface TopLevelElement {
12+export type TopLevelUnion = PurpleTopLevel[] | FluffyTopLevel | string;
13+
14+export interface PurpleTopLevel {
1315 ALIENLEVEL: number;
1416 BREED: Breed;
1517 CHAR_DIMENSION: number;
@@ -41,7 +43,7 @@ export type RankTitle = "President" | "Advisor" | "Veteran" | "Applicant";
4143
4244 export type Sex = "Neuter" | "Male" | "Female";
4345
44-export interface PurpleTopLevel {
46+export interface FluffyTopLevel {
4547 ADVENTURERCOUNT: number;
4648 AGENTCOUNT: number;
4749 ATROXCOUNT: number;
@@ -82,12 +84,12 @@ export interface PurpleTopLevel {
8284 // Converts JSON strings to/from your types
8385 // and asserts the results of JSON.parse at runtime
8486 export class Convert {
85- public static toTopLevel(json: string): TopLevel[] {
86- return cast(JSON.parse(json), a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), "")));
87+ public static toTopLevel(json: string): TopLevelUnion[] {
88+ return cast(JSON.parse(json), a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), "")));
8789 }
8890
89- public static topLevelToJson(value: TopLevel[]): string {
90- return JSON.stringify(uncast(value, a(u(a(r("TopLevelElement")), r("PurpleTopLevel"), ""))), null, 2);
91+ public static topLevelToJson(value: TopLevelUnion[]): string {
92+ return JSON.stringify(uncast(value, a(u(a(r("PurpleTopLevel")), r("FluffyTopLevel"), ""))), null, 2);
9193 }
9294 }
9395
@@ -245,7 +247,7 @@ function r(name: string) {
245247 }
246248
247249 const typeMap: any = {
248- "TopLevelElement": o([
250+ "PurpleTopLevel": o([
249251 { json: "ALIENLEVEL", js: "ALIENLEVEL", typ: 0 },
250252 { json: "BREED", js: "BREED", typ: r("Breed") },
251253 { json: "CHAR_DIMENSION", js: "CHAR_DIMENSION", typ: 0 },
@@ -264,7 +266,7 @@ const typeMap: any = {
264266 { json: "RANK_TITLE", js: "RANK_TITLE", typ: r("RankTitle") },
265267 { json: "SEX", js: "SEX", typ: r("Sex") },
266268 ], false),
267- "PurpleTopLevel": o([
269+ "FluffyTopLevel": o([
268270 { json: "ADVENTURERCOUNT", js: "ADVENTURERCOUNT", typ: 0 },
269271 { json: "AGENTCOUNT", js: "AGENTCOUNT", typ: 0 },
270272 { json: "ATROXCOUNT", js: "ATROXCOUNT", typ: 0 },
Test case

test/inputs/json/priority/issue2680-object-array.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,18 +9,20 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 key: string;
1416 };
1517
1618 // Converts JSON strings to/from your types
1719 // and asserts the results of JSON.parse at runtime
18-function toTopLevel(json: string): TopLevel[] {
19- return cast(JSON.parse(json), a(r("TopLevel")));
20+function toTopLevel(json: string): TopLevelElement[] {
21+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2022 }
2123
22-function topLevelToJson(value: TopLevel[]): string {
23- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
24+function topLevelToJson(value: TopLevelElement[]): string {
25+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2426 }
2527
2628 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -177,7 +179,7 @@ function r(name: string) {
177179 }
178180
179181 const typeMap: any = {
180- "TopLevel": o([
182+ "TopLevelElement": o([
181183 { json: "key", js: "key", typ: "" },
182184 ], false),
183185 };
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "key", js: "key", typ: "" },
176176 ], false),
177177 };
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,19 +7,21 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 key: string;
1214 }
1315
1416 // Converts JSON strings to/from your types
1517 // and asserts the results of JSON.parse at runtime
1618 export class Convert {
17- public static toTopLevel(json: string): TopLevel[] {
18- return cast(JSON.parse(json), a(r("TopLevel")));
19+ public static toTopLevel(json: string): TopLevelElement[] {
20+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1921 }
2022
21- public static topLevelToJson(value: TopLevel[]): string {
22- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
23+ public static topLevelToJson(value: TopLevelElement[]): string {
24+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2325 }
2426 }
2527
@@ -177,7 +179,7 @@ function r(name: string) {
177179 }
178180
179181 const typeMap: any = {
180- "TopLevel": o([
182+ "TopLevelElement": o([
181183 { json: "key", js: "key", typ: "" },
182184 ], false),
183185 };
Test case

test/inputs/json/priority/issue2680-scalar-array.json

2 generated files · +4 −0
Mflowdefault / TopLevel.js+2 −0
@@ -9,6 +9,8 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12+export type TopLevel = number[];
13+
1214 // Converts JSON strings to/from your types
1315 // and asserts the results of JSON.parse at runtime
1416 function toTopLevel(json: string): number[] {
Mtypescriptdefault / TopLevel.ts+2 −0
@@ -7,6 +7,8 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10+export type TopLevel = number[];
11+
1012 // Converts JSON strings to/from your types
1113 // and asserts the results of JSON.parse at runtime
1214 export class Convert {
Test case

test/inputs/json/priority/kotlin-enum-class-case-collision.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 category: Category;
1416 };
1517
@@ -19,12 +21,12 @@ export type Category =
1921
2022 // Converts JSON strings to/from your types
2123 // and asserts the results of JSON.parse at runtime
22-function toTopLevel(json: string): TopLevel[] {
23- return cast(JSON.parse(json), a(r("TopLevel")));
24+function toTopLevel(json: string): TopLevelElement[] {
25+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2426 }
2527
26-function topLevelToJson(value: TopLevel[]): string {
27- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
28+function topLevelToJson(value: TopLevelElement[]): string {
29+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2830 }
2931
3032 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -181,7 +183,7 @@ function r(name: string) {
181183 }
182184
183185 const typeMap: any = {
184- "TopLevel": o([
186+ "TopLevelElement": o([
185187 { json: "category", js: "category", typ: r("Category") },
186188 ], false),
187189 "Category": [
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "category", js: "category", typ: r("Category") },
176176 ], false),
177177 "Category": [
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 category: Category;
1214 }
1315
@@ -16,12 +18,12 @@ export type Category = " " | "";
1618 // Converts JSON strings to/from your types
1719 // and asserts the results of JSON.parse at runtime
1820 export class Convert {
19- public static toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+ public static toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23- public static topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+ public static topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628 }
2729
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "category", js: "category", typ: r("Category") },
184186 ], false),
185187 "Category": [
Test case

test/inputs/json/priority/optional-union.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 a?: A;
1416 };
1517
@@ -17,12 +19,12 @@ export type A = number | string;
1719
1820 // Converts JSON strings to/from your types
1921 // and asserts the results of JSON.parse at runtime
20-function toTopLevel(json: string): TopLevel[] {
21- return cast(JSON.parse(json), a(r("TopLevel")));
22+function toTopLevel(json: string): TopLevelElement[] {
23+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2224 }
2325
24-function topLevelToJson(value: TopLevel[]): string {
25- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
26+function topLevelToJson(value: TopLevelElement[]): string {
27+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2628 }
2729
2830 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "a", js: "a", typ: u(undefined, u(0, "")) },
184186 ], false),
185187 };
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "a", js: "a", typ: u(undefined, u(0, "")) },
176176 ], false),
177177 };
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 a?: A;
1214 }
1315
@@ -16,12 +18,12 @@ export type A = number | string;
1618 // Converts JSON strings to/from your types
1719 // and asserts the results of JSON.parse at runtime
1820 export class Convert {
19- public static toTopLevel(json: string): TopLevel[] {
20- return cast(JSON.parse(json), a(r("TopLevel")));
21+ public static toTopLevel(json: string): TopLevelElement[] {
22+ return cast(JSON.parse(json), a(r("TopLevelElement")));
2123 }
2224
23- public static topLevelToJson(value: TopLevel[]): string {
24- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
25+ public static topLevelToJson(value: TopLevelElement[]): string {
26+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
2527 }
2628 }
2729
@@ -179,7 +181,7 @@ function r(name: string) {
179181 }
180182
181183 const typeMap: any = {
182- "TopLevel": o([
184+ "TopLevelElement": o([
183185 { json: "a", js: "a", typ: u(undefined, u(0, "")) },
184186 ], false),
185187 };
Test case

test/inputs/json/samples/github-events.json

3 generated files · +19 −15
Mflowdefault / TopLevel.js+8 −6
@@ -9,7 +9,9 @@
99 // These functions will throw an error if the JSON doesn't
1010 // match the expected interface, even if the JSON is valid.
1111
12-export type TopLevel = {
12+export type TopLevel = TopLevelElement[];
13+
14+export type TopLevelElement = {
1315 actor: Actor;
1416 created_at: Date;
1517 id: string;
@@ -301,12 +303,12 @@ export type TopLevelRepo = {
301303
302304 // Converts JSON strings to/from your types
303305 // and asserts the results of JSON.parse at runtime
304-function toTopLevel(json: string): TopLevel[] {
305- return cast(JSON.parse(json), a(r("TopLevel")));
306+function toTopLevel(json: string): TopLevelElement[] {
307+ return cast(JSON.parse(json), a(r("TopLevelElement")));
306308 }
307309
308-function topLevelToJson(value: TopLevel[]): string {
309- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
310+function topLevelToJson(value: TopLevelElement[]): string {
311+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
310312 }
311313
312314 function invalidValue(typ: any, val: any, key: any, parent: any = '') {
@@ -463,7 +465,7 @@ function r(name: string) {
463465 }
464466
465467 const typeMap: any = {
466- "TopLevel": o([
468+ "TopLevelElement": o([
467469 { json: "actor", js: "actor", typ: r("Actor") },
468470 { json: "created_at", js: "created_at", typ: Date },
469471 { json: "id", js: "id", typ: "" },
Mjavascriptdefault / TopLevel.js+3 −3
@@ -10,11 +10,11 @@
1010 // Converts JSON strings to/from your types
1111 // and asserts the results of JSON.parse at runtime
1212 function toTopLevel(json) {
13- return cast(JSON.parse(json), a(r("TopLevel")));
13+ return cast(JSON.parse(json), a(r("TopLevelElement")));
1414 }
1515
1616 function topLevelToJson(value) {
17- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
17+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
1818 }
1919
2020 function invalidValue(typ, val, key, parent = '') {
@@ -171,7 +171,7 @@ function r(name) {
171171 }
172172
173173 const typeMap = {
174- "TopLevel": o([
174+ "TopLevelElement": o([
175175 { json: "actor", js: "actor", typ: r("Actor") },
176176 { json: "created_at", js: "created_at", typ: Date },
177177 { json: "id", js: "id", typ: "" },
Mtypescriptdefault / TopLevel.ts+8 −6
@@ -7,7 +7,9 @@
77 // These functions will throw an error if the JSON doesn't
88 // match the expected interface, even if the JSON is valid.
99
10-export interface TopLevel {
10+export type TopLevel = TopLevelElement[];
11+
12+export interface TopLevelElement {
1113 actor: Actor;
1214 created_at: Date;
1315 id: string;
@@ -298,12 +300,12 @@ export interface TopLevelRepo {
298300 // Converts JSON strings to/from your types
299301 // and asserts the results of JSON.parse at runtime
300302 export class Convert {
301- public static toTopLevel(json: string): TopLevel[] {
302- return cast(JSON.parse(json), a(r("TopLevel")));
303+ public static toTopLevel(json: string): TopLevelElement[] {
304+ return cast(JSON.parse(json), a(r("TopLevelElement")));
303305 }
304306
305- public static topLevelToJson(value: TopLevel[]): string {
306- return JSON.stringify(uncast(value, a(r("TopLevel"))), null, 2);
307+ public static topLevelToJson(value: TopLevelElement[]): string {
308+ return JSON.stringify(uncast(value, a(r("TopLevelElement"))), null, 2);
307309 }
308310 }
309311
@@ -461,7 +463,7 @@ function r(name: string) {
461463 }
462464
463465 const typeMap: any = {
464- "TopLevel": o([
466+ "TopLevelElement": o([
465467 { json: "actor", js: "actor", typ: r("Actor") },
466468 { json: "created_at", js: "created_at", typ: Date },
467469 { json: "id", js: "id", typ: "" },
No generated files match these filters.