JSON से C# क्लास
JSON को System.Text.Json या Newtonsoft.Json के लिए C# क्लास या record में बदलें, nullable टाइप, JsonPropertyName attribute और DateTimeOffset/Guid पहचान के साथ।
For strings that look like dates and UUIDs
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
public class Root
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("username")]
public string Username { get; set; } = string.Empty;
[JsonPropertyName("email")]
public string Email { get; set; } = string.Empty;
[JsonPropertyName("isActive")]
public bool IsActive { get; set; }
[JsonPropertyName("rating")]
public double Rating { get; set; }
[JsonPropertyName("createdAt")]
public DateTimeOffset CreatedAt { get; set; }
[JsonPropertyName("avatarUrl")]
public object? AvatarUrl { get; set; }
[JsonPropertyName("tags")]
public List<string> Tags { get; set; } = new();
[JsonPropertyName("address")]
public Address Address { get; set; } = new();
[JsonPropertyName("orders")]
public List<Order> Orders { get; set; } = new();
}
public class Address
{
[JsonPropertyName("street")]
public string Street { get; set; } = string.Empty;
[JsonPropertyName("city")]
public string City { get; set; } = string.Empty;
[JsonPropertyName("zipCode")]
public string ZipCode { get; set; } = string.Empty;
}
public class Order
{
[JsonPropertyName("orderId")]
public string OrderId { get; set; } = string.Empty;
[JsonPropertyName("total")]
public double Total { get; set; }
[JsonPropertyName("items")]
public int Items { get; set; }
[JsonPropertyName("shipped")]
public bool Shipped { get; set; }
[JsonPropertyName("coupon")]
public string? Coupon { get; set; }
}
Arrays of objects are merged: a key missing from some items becomes optional, null makes a field nullable, and identical shapes share one type. Paste several examples in an array for the most accurate types.
इस टूल के बारे में
JSON पेस्ट करें और System.Text.Json या Newtonsoft.Json के लिए तैयार C# क्लास या record पाएँ। प्रॉपर्टी PascalCase में होती हैं और उन पर [JsonPropertyName] या [JsonProperty] attribute लगे होते हैं, ताकि हर key ठीक वैसे ही वापस मैप हो। nullable reference types सही तरीके से इस्तेमाल होते हैं: वैकल्पिक और null वैल्यू nullable बनती हैं, और non-null स्ट्रिंग, लिस्ट और ऑब्जेक्ट को शुरुआती वैल्यू मिलती है ताकि कंपाइलर कोई CS8618 चेतावनी न दे। पूर्णांक वैल्यू के हिसाब से int या long बनते हैं, दशमलव संख्याएँ double, और जो स्ट्रिंग टाइमस्टैम्प, तारीख़ या UUID जैसी दिखती हैं वे DateTimeOffset, DateOnly या Guid बन सकती हैं। नेस्टेड ऑब्जेक्ट को अपनी क्लास मिलती है, लिस्ट List<T> बनती हैं, और ID को key बनाकर रखे गए ऑब्जेक्ट Dictionary<string, T> बनते हैं। file-scoped namespace चुनें और इसी पेज से Go, Rust, Python या Kotlin पर स्विच करें।
JSON को C# क्लास में कैसे बदलें
JSON सैंपल से C# टाइप बनाएँ।
- 1
JSON पेस्ट करें
एक JSON ऑब्जेक्ट या उदाहरणों का ऐरे पेस्ट करें।
- 2
विकल्प चुनें
System.Text.Json या Newtonsoft, class या record, और एक namespace चुनें।
- 3
कोड कॉपी करें
क्लास कॉपी करें या Types.cs डाउनलोड करें।