CMD Simulator

Null Values & Optional Fields – JSON to Typedef Example

Demonstrate how null values in JSON are converted to optional fields in TypeScript (?) and nullable types in C# (?). Essential for API response typing.

What this demonstrates: This example has many null fields at different levels. In TypeScript, each null field becomes optional (?) with type | null. In C#, value types like bool become bool? while string remains as-is. This pattern is common in API responses where fields may not be populated.

JSON Input
TypeScript Output

Paste JSON on the left to generate typedefs

Supports Nested Objects and Arrays

Our converter recursively processes deeply nested JSON structures, including arrays of objects, mixed-type arrays, and multi-level object hierarchies. Each nested object gets its own named interface (TypeScript) or class (C#) with properly typed properties.

Optional Fields and Mixed Types Handled

When a field is null in your JSON, it's automatically marked as optional in TypeScript (with ?) or nullable in C#. Arrays with mixed element types produce union types or fallback to object.

How to Use This JSON to Typedef Converter

1

Paste JSON

Paste or type your JSON into the input area on the left.

2

Choose Language

Select TypeScript or C# from the dropdown.

3

Copy Output

Your type definitions appear instantly. Click Copy to use them.