CMD Simulator

JSON Data Types Explained for Developers

Complete guide to JSON data types: strings, numbers, booleans, null, objects, and arrays. Understand how each type maps to TypeScript and C# when generating type definitions.

The Six JSON Data Types

JSON (JavaScript Object Notation) has exactly six data types. Understanding them is essential for generating accurate type definitions.


1. String

Strings are enclosed in double quotes. They support Unicode and escape sequences.

{ "name": "Alice", "emoji": "👋", "path": "C:\\Users" }
TargetGenerated Type
TypeScriptstring
C#string

2. Number

JSON doesn't distinguish between integers and floats — both are "number." Our converter infers the distinction from the value:

{ "count": 42, "price": 19.99, "scientific": 1.5e10 }
ValueTypeScriptC#
Integer (42)numberint
Decimal (19.99)numberdouble

3. Boolean

Simple true/false values:

{ "isActive": true, "isDeleted": false }
TargetGenerated Type
TypeScriptboolean
C#bool

4. Null

Null represents the absence of a value. It's critical for type generation because it signals optionality:

{ "middleName": null, "deletedAt": null }
TargetGenerated Type
TypeScriptOptional (?) with `
C#Nullable (? for value types)

5. Object

Objects are key-value pairs enclosed in curly braces. Keys must be strings:

{
  "address": {
    "street": "123 Main St",
    "city": "Portland"
  }
}

Each object becomes a separate interface (TypeScript) or class (C#) with its own named type.


6. Array

Arrays are ordered lists enclosed in square brackets. They can contain any JSON type:

{
  "tags": ["dev", "prod"],
  "scores": [95, 87, 92],
  "matrix": [[1, 2], [3, 4]],
  "mixed": [1, "two", null]
}
Array TypeTypeScriptC#
Homogeneousstring[]List<string>
ObjectsItem[]List<Item>
Mixed(type1 | type2)[]List<object>
Emptyunknown[]List<object>

Type Inference Strategy

Our converter uses these rules to infer types:

  1. Examine all elements in arrays to determine the element type
  2. Merge object shapes when multiple objects appear in the same array
  3. Mark as optional when a field is null or missing from some array elements
  4. Create separate types for each unique nested object structure
  5. Use union types in TypeScript when array elements have different types

Understanding these rules helps you predict and validate the generated output.

Ready to try it?

Open the Converter →