-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.html
More file actions
279 lines (256 loc) · 14.7 KB
/
Copy pathcode.html
File metadata and controls
279 lines (256 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSON to C#, TypeScript, Dart, Kotlin, Java, Python & Go classes | JSON Studio</title>
<meta name="description" content="Generate typed classes from a JSON sample: C# with System.Text.Json attributes, TypeScript interfaces, Dart with fromJson/toJson, Kotlin data classes, Java POJOs, Python dataclasses and Go structs. Free and client-side.">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://jsonstudio.msdevbuild.com/code.html">
<link rel="manifest" href="manifest.webmanifest">
<meta name="theme-color" content="#0078d4" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#12151c" media="(prefers-color-scheme: dark)">
<link rel="apple-touch-icon" href="assets/img/apple-touch-icon.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="JSON Studio">
<link rel="icon" href="assets/img/favicon.svg" type="image/svg+xml">
<meta property="og:type" content="website">
<meta property="og:title" content="JSON to C#, TypeScript, Dart, Kotlin, Java, Python & Go classes">
<meta property="og:description" content="Generate typed classes from a JSON sample: C# with System.Text.Json attributes, TypeScript interfaces, Dart with fromJson/toJson, Kotlin data classes, Java POJOs, Python dataclasses and Go structs. Free and client-side.">
<meta property="og:url" content="https://jsonstudio.msdevbuild.com/code.html">
<meta property="og:image" content="https://jsonstudio.msdevbuild.com/assets/img/og-cover.png">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:image:alt" content="JSON Studio — every JSON tool, in your browser">
<meta property="og:site_name" content="JSON Studio by MSDEVBUILD">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://jsonstudio.msdevbuild.com/assets/img/og-cover.png">
<meta name="twitter:title" content="JSON to C#, TypeScript, Dart, Kotlin, Java, Python & Go classes">
<meta name="twitter:description" content="Generate typed classes from a JSON sample: C# with System.Text.Json attributes, TypeScript interfaces, Dart with fromJson/toJson, Kotlin data classes, Java POJOs, Python dataclasses and Go structs. Free and client-side.">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/styles.css">
<link rel="stylesheet" href="assets/css/convert.css">
<link rel="stylesheet" href="assets/css/present.css">
<link rel="stylesheet" href="assets/css/workbench.css">
<link rel="stylesheet" href="assets/css/tool-focus.css">
<link rel="stylesheet" href="assets/css/editor.css">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "SoftwareApplication",
"name": "JSON to C#, TypeScript, Dart, Kotlin, Java, Python & Go — JSON Studio",
"url": "https://jsonstudio.msdevbuild.com/code.html",
"applicationCategory": "DeveloperApplication",
"operatingSystem": "Any (runs in browser)",
"offers": { "@type": "Offer", "price": "0", "priceCurrency": "USD" },
"creator": { "@type": "Person", "name": "Suthahar Jegatheesan", "url": "https://www.msdevbuild.com/" },
"description": "Generate typed classes from a JSON sample: C# records, TypeScript interfaces, Dart, Kotlin, Java, Python dataclasses and Go structs. Free, client-side."
}
</script>
<script>(function(){try{var t=localStorage.getItem('json-studio-theme');if(!t&&window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)t='dark';if(t)document.documentElement.setAttribute('data-theme',t);}catch(e){}})();</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "BreadcrumbList",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "JSON Studio", "item": "https://jsonstudio.msdevbuild.com/" },
{ "@type": "ListItem", "position": 2, "name": "Tools", "item": "https://jsonstudio.msdevbuild.com/tools.html" },
{ "@type": "ListItem", "position": 3, "name": "JSON to code", "item": "https://jsonstudio.msdevbuild.com/code.html" }
]
},
{
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "Which languages are supported?", "acceptedAnswer": { "@type": "Answer", "text": "C#, TypeScript, Dart, Kotlin, Java, Python and Go. C# emits [JsonPropertyName], Kotlin @SerialName, Java @JsonProperty, Go json tags with omitempty, and Dart gets fromJson/toJson methods." } },
{ "@type": "Question", "name": "How are optional fields handled?", "acceptedAnswer": { "@type": "Answer", "text": "A key missing from any element of an array is treated as optional: nullable in C# and Kotlin, `?` in TypeScript, Optional[...] with a default in Python, a pointer in Go." } },
{ "@type": "Question", "name": "What happens with mixed types?", "acceptedAnswer": { "@type": "Answer", "text": "integer and floating-point values in the same position widen to the language's floating type. Genuinely mixed types (a string and an object, say) fall back to the language's open type — object, unknown, dynamic or interface{}." } }
]
},
{
"@type": "HowTo",
"name": "How to use the JSON to code",
"step": [
{ "@type": "HowToStep", "position": 1, "text": "Paste a representative payload — include elements with optional fields present and absent." },
{ "@type": "HowToStep", "position": 2, "text": "Pick the language, name the root type, and choose whether to emit serialisation annotations and nullable optionals." },
{ "@type": "HowToStep", "position": 3, "text": "Copy the code, or download it as a file named after the root type." }
]
}
]
}
</script>
</head>
<body>
<div id="site-header"></div>
<span id="top"></span>
<main class="convert-shell">
<div class="convert-head">
<div class="container tool-topbar">
<h1>JSON to code</h1>
<p class="tt-sub">Typed classes for C#, TypeScript, Dart, Kotlin, Java, Python or Go.</p>
<a class="tt-about" href="#about">About & FAQ ↓</a>
</div>
<div class="container">
<div class="opt-bar">
<div class="opt">
<label for="opt-lang">Language</label>
<select id="opt-lang">
<option value="csharp" selected>C#</option>
<option value="typescript">TypeScript</option>
<option value="dart">Dart</option>
<option value="kotlin">Kotlin</option>
<option value="java">Java</option>
<option value="python">Python</option>
<option value="go">Go</option>
</select>
</div>
<div class="opt">
<label for="opt-root">Root name</label>
<input type="text" id="opt-root" value="Root">
</div>
<div class="opt-sep"></div>
<div class="opt">
<input type="checkbox" id="opt-attrs" checked>
<label for="opt-attrs" style="cursor:pointer;">Serialization annotations</label>
</div>
<div class="opt">
<input type="checkbox" id="opt-nullable" checked>
<label for="opt-nullable" style="cursor:pointer;">Optional fields nullable</label>
</div>
<div class="opt">
<input type="checkbox" id="opt-pascal" checked>
<label for="opt-pascal" style="cursor:pointer;">Idiomatic member names</label>
</div>
</div>
</div>
</div>
<div class="convert-grid">
<section class="pane">
<div class="pane-head">
<div class="pane-title">Sample JSON</div>
<button id="btn-sample">Load sample</button>
<button id="btn-upload">Upload</button>
<button id="btn-clear">Clear</button>
<input type="file" id="file-input" accept=".json,application/json" style="display:none;">
</div>
<div class="pane-body">
<textarea id="input" class="code-area" spellcheck="false" placeholder="{"paste a representative payload here": true}"></textarea>
</div>
<div class="pane-status" id="in-status">Waiting for input.</div>
</section>
<section class="pane">
<div class="pane-head">
<div class="pane-title">Generated code</div>
<button class="primary" id="btn-run">Generate</button>
<button id="btn-copy">Copy</button>
<button id="btn-download">Download</button>
</div>
<div class="pane-body">
<textarea id="output" class="code-area" spellcheck="false" readonly placeholder="Generated classes appear here."></textarea>
<p class="note">Generated from one sample, so treat optionality and numeric widths as a first draft.</p>
</div>
<div class="pane-status" id="out-status"></div>
</section>
</div>
</main>
<section class="tool-home" id="about">
<div class="container">
<div class="th-more">Reference</div>
<header class="th-head">
<div class="kicker">JSON to code</div>
<h2>About the JSON to code generator</h2>
<p>Turning an API response into model classes by hand is busywork. Paste the payload and get types for your language, with the serialisation attributes that language expects. Array elements are merged before generating, so a key that appears in only some elements becomes an optional field rather than being lost — the mistake most generators make when they read only the first element.</p>
<div class="cta-row">
<a class="btn-primary" href="#top">Use the tool ↑</a>
<a class="btn-secondary btn-present" href="presentation.html"><svg class="nav-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="13" rx="2"/><path d="M12 17v3M9.5 20h5"/><path d="m10.6 8.8 4 2.7-4 2.7z" fill="currentColor" stroke="none"/></svg> Present it</a>
</div>
</header>
<div class="th-features">
<div class="th-feature">
<div class="fi">01</div>
<h3>Seven languages</h3>
<p>C#, TypeScript, Dart, Kotlin, Java, Python and Go, each with idiomatic naming.</p>
</div>
<div class="th-feature">
<div class="fi">02</div>
<h3>Serialisation attributes</h3>
<p>JsonPropertyName, SerialName, JsonProperty, json tags — the annotation your stack expects.</p>
</div>
<div class="th-feature">
<div class="fi">03</div>
<h3>Optionality preserved</h3>
<p>A key missing from some array elements becomes an optional or nullable field, not a lost one.</p>
</div>
<div class="th-feature">
<div class="fi">04</div>
<h3>Nested types named</h3>
<p>Nested objects become their own classes, singularised from the property that held them.</p>
</div>
</div>
<div class="seo-grid">
<div class="seo-main">
<h3 id="how">How to use it</h3>
<ol class="seo-steps">
<li>Paste a representative payload — include elements with optional fields present and absent.</li>
<li>Pick the language, name the root type, and choose whether to emit serialisation annotations and nullable optionals.</li>
<li>Copy the code, or download it as a file named after the root type.</li>
</ol>
<h3 id="faq">Questions</h3>
<div class="faq">
<details>
<summary>Which languages are supported?</summary>
<div class="faq-body"><p>C#, TypeScript, Dart, Kotlin, Java, Python and Go. C# emits [JsonPropertyName], Kotlin @SerialName, Java @JsonProperty, Go json tags with omitempty, and Dart gets fromJson/toJson methods.</p></div>
</details>
<details>
<summary>How are optional fields handled?</summary>
<div class="faq-body"><p>A key missing from any element of an array is treated as optional: nullable in C# and Kotlin, `?` in TypeScript, Optional[...] with a default in Python, a pointer in Go.</p></div>
</details>
<details>
<summary>What happens with mixed types?</summary>
<div class="faq-body"><p>integer and floating-point values in the same position widen to the language's floating type. Genuinely mixed types (a string and an object, say) fall back to the language's open type — object, unknown, dynamic or interface{}.</p></div>
</details>
</div>
</div>
<aside class="seo-side">
<div class="seo-card" id="share">
<h3>Share this tool</h3>
<p>Send it to a colleague — the link only, never anything you have pasted in.</p>
<div data-share data-share-title="JSON to code — JSON Studio"></div>
</div>
<div class="seo-card">
<h3 class="with-ico"><svg class="nav-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="13" rx="2"/><path d="M12 17v3M9.5 20h5"/><path d="m10.6 8.8 4 2.7-4 2.7z" fill="currentColor" stroke="none"/></svg> Present this tool</h3>
<p>Demoing to a client or a class? Press <kbd>Shift</kbd><kbd>P</kbd> for full-screen presentation mode — chrome hidden, type scaled up, laser pointer included.</p>
<a class="seo-link" href="presentation.html">How presentation mode works →</a>
</div>
<div class="seo-card">
<h3>Related tools</h3>
<ul class="seo-related">
<li><a href="json-schema.html"><span class="ri">Sχ</span>Schema generator</a></li>
<li><a href="format.html"><span class="ri">⌗</span>Formatter & validator</a></li>
<li><a href="csv.html"><span class="ri">J↔C</span>JSON ⇄ CSV</a></li>
</ul>
<a class="seo-link" href="tools.html">All 14 tools →</a>
</div>
<div class="seo-card quiet">
<h3>Private by construction</h3>
<p>No backend exists. Everything on this page runs in your browser, so nothing you paste is uploaded, logged or retained.</p>
<a class="seo-link" href="privacy.html">Read the privacy policy →</a>
</div>
</aside>
</div>
</div>
</section>
<div id="site-footer"></div>
<script src="assets/js/site.js"></script>
<script src="assets/js/payload-link.js"></script>
<script src="assets/js/tool-kit.js"></script>
<script src="assets/js/infer.js"></script>
<script src="assets/js/code.js"></script>
<script src="assets/js/present.js"></script>
<script src="assets/js/workbench.js"></script>
<script src="assets/js/history.js"></script>
<script src="assets/js/gutter.js"></script>
<script src="assets/js/editor.js"></script>
<script src="assets/js/share.js"></script>
</body>
</html>