JSON Converters Code Gen Formatters All tools Browse all tools built byAbhay Darji

YAML to C# Converter

Generate C# types from YAML instantly. Optional fields are detected automatically. Runs entirely in your browser.

100% client side No upload No size limit Works offline
Input
Output
Ready
Drop a file to load it

About this tool

Paste a YAML sample and get C# type definitions you can use immediately. Emits classes with auto-properties and `[JsonPropertyName]` attributes for `System.Text.Json`.

When you would use it

  • Deserialising in .NET without a custom naming policy
  • Bootstrapping models from a real YAML response instead of writing them by hand
  • Keeping types in step with an API that has changed

Worked example

YAML
id: 4815
name: Ada Lovelace
active: true
score: 91.5
roles:
  - admin
  - editor
address:
  city: London
  postcode: NW1
C#
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Root
{
    [JsonPropertyName("id")]
    public long Id { get; set; }

    [JsonPropertyName("name")]
    public string Name { get; set; }

    [JsonPropertyName("active")]
    public bool Active { get; set; }

    [JsonPropertyName("score")]
    public double Score { get; set; }

    [JsonPropertyName("roles")]
    public List<string> Roles { get; set; }

    [JsonPropertyName("address")]
    public Address Address { get; set; }

}
public class Address
{
    [JsonPropertyName("city")]
    public string City { get; set; }

    [JsonPropertyName("postcode")]
    public string Postcode { get; set; }

}

Things worth knowing

  • Every object in an array is merged when inferring the shape, so a field missing from one item is marked optional rather than assumed to always be present.
  • Identical nested shapes are de-duplicated into a single type instead of generating near-duplicates.
  • Array element types are named from the singular of the field name, so posts produces a Post type.
  • YAML resolves unquoted scalars to types, so no becomes a boolean and 1.10 becomes a number. Quote values you want treated as text.
Questions

Frequently asked

How are optional fields detected?
By comparing every object in an array. A key present in some records but not others becomes optional; a key present in all of them is required. This is why passing several records gives better results than one.
Can it handle deeply nested YAML?
Yes. Nested objects become separate named types, referenced from their parent, at any depth.
Is my data uploaded anywhere?
No. Every tool on JSONWorks runs entirely in your browser using JavaScript. Your input is never sent to a server, never logged and never stored. The simplest proof is to disconnect from the internet — the tools keep working. The site does load Google Fonts and a Google Analytics page-view tag, so you will see those two requests in your network tab, but neither receives anything you type or paste.
Related

Tools that pair well with this