JSON से Go Struct
JSON को json टैग वाले Go struct में बदलें, gofmt की तरह अलाइन किए हुए। वैकल्पिक फ़ील्ड omitempty के साथ पॉइंटर बनते हैं; टाइमस्टैम्प time.Time बन सकते हैं।
*string tells “missing or null” apart from “”
Off uses int
RFC 3339 strings like 2026-03-14T09:26:53Z
package main
import "time"
type Root struct {
ID int64 `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
IsActive bool `json:"isActive"`
Rating float64 `json:"rating"`
CreatedAt time.Time `json:"createdAt"`
AvatarURL any `json:"avatarUrl"`
Tags []string `json:"tags"`
Address Address `json:"address"`
Orders []Order `json:"orders"`
}
type Address struct {
Street string `json:"street"`
City string `json:"city"`
ZipCode string `json:"zipCode"`
}
type Order struct {
OrderID string `json:"orderId"`
Total float64 `json:"total"`
Items int64 `json:"items"`
Shipped bool `json:"shipped"`
Coupon *string `json:"coupon,omitempty"`
}
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 पेस्ट करें और ऐसे Go struct पाएँ जिन्हें आप सीधे अपने कोड में डाल सकें। फ़ील्ड के नाम ID, URL और API जैसे initialisms के साथ Go के नियमों का पालन करते हैं, हर फ़ील्ड का json टैग होता है, और आउटपुट ठीक वैसे ही अलाइन होता है जैसे gofmt उसे फ़ॉर्मेट करता। ऑब्जेक्ट के ऐरे मिलाए जाते हैं, इसलिए जो key कुछ आइटम में नहीं होती वह वैकल्पिक बन जाती है (omitempty वाला पॉइंटर), null किसी फ़ील्ड को nullable बनाता है, और 10.0 जैसी वैल्यू में भी पूर्णांक और दशमलव संख्याओं को अलग पहचाना जाता है। नेस्टेड ऑब्जेक्ट अपने नाम वाले अलग टाइप बनते हैं, एक जैसी बनावट वाले ऑब्जेक्ट एक ही टाइप साझा करते हैं, और ID को key बनाकर रखे गए ऑब्जेक्ट map बन जाते हैं। विकल्पों से पैकेज का नाम, पॉइंटर, omitempty, int या int64 और RFC 3339 टाइमस्टैम्प के लिए time.Time चुनें। आप इसी पेज से Rust, C#, Python या Kotlin पर स्विच कर सकते हैं।
JSON को Go struct में कैसे बदलें
JSON सैंपल से Go टाइप बनाएँ।
- 1
JSON पेस्ट करें
एक JSON ऑब्जेक्ट पेस्ट करें, या सबसे सटीक टाइप के लिए उदाहरणों का ऐरे।
- 2
विकल्प चुनें
रूट टाइप का नाम, पैकेज, पॉइंटर, omitempty और time.Time सेट करें।
- 3
कोड कॉपी करें
struct कॉपी करें या types.go डाउनलोड करें।