b2KIT

JSON to C# Class

Generate C# class definitions from JSON with property attributes, nullable types, and JsonProperty annotations.

Tested tool guide Tested browser tools Checked August 16, 2026

What JSON to C# Class does and how it behaves

JSON to C# Class converts the structure observed in pasted JSON into C# class definitions suitable for DTOs or POCOs. It infers properties and candidate C# types from JSON values, represents nested objects with related classes, and can include nullable types, property attributes, and Newtonsoft.Json JsonProperty annotations. The important limitation is that a sample is not a contract: missing properties, nullability, numeric range, and alternative object shapes cannot be determined reliably from one example.

How the result is produced

1

Structure and type inference

The converter examines JSON objects, arrays, strings, numbers, booleans, and null values, then expresses the observed structure as C# properties and class definitions. Nested objects can require additional class types, while array contents provide evidence for an element type. The result describes the supplied instance, so properties or value forms absent from that instance cannot influence the generated model.

2

Names, attributes, and nullability

Generated property attributes can preserve the connection between a JSON member name and its C# property. In particular, JsonProperty annotations identify Newtonsoft.Json member names when the JSON spelling should be retained independently of the C# identifier. Nullable output expresses permitted null values at the C# type level, but it should be reviewed against the actual data contract rather than accepted solely from one sample.

Good uses

  • Create an initial set of DTO or POCO classes from a documented JSON request or response before adding validation, constructors, and application-specific behavior.
  • Model a third-party Newtonsoft.Json payload whose member names use underscores, hyphens, reserved words, or casing that should not dictate the final C# property names.
  • Turn a captured API example into editable C# types for a prototype, test fixture, migration utility, or one-off data import.

Limits and checks

  • Inference is limited to the pasted sample. A property missing from that sample will not be discovered, and a property seen once as non-null does not prove that null is impossible.
  • JSON numbers do not declare C# storage widths. Confirm generated numeric types against documented ranges, decimal precision requirements, and values not represented in the sample.
  • Mixed-type arrays and objects whose shapes vary between records may not fit one generated element class. Review such collections manually, especially when fields appear conditionally.

Common questions

Does the generated code guarantee that every payload will deserialize?

No. The classes reflect the structure and values available in the input example, not every payload permitted by the producer. Compare the result with the API or file-format contract, test additional samples, and review dates, enums, numbers, optional members, polymorphic objects, and serializer settings. Custom converters may still be necessary for representations that ordinary property types cannot capture.

Does JsonProperty make the class compatible with System.Text.Json?

No. JsonPropertyAttribute belongs to Newtonsoft.Json. System.Text.Json uses its own attributes, including JsonPropertyNameAttribute, and does not treat a Newtonsoft.Json JsonProperty annotation as an equivalent name mapping. If the target project uses System.Text.Json, replace or omit Newtonsoft-specific annotations and review the resulting naming and null-handling behavior under that serializer.

References and verification

The behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools