JSON Rotation Go Structure Complete Guide
This tool converts the JSON sample to Go struct Define, easily docking API. Paste JSON on the left, get Go code on the right. Set root structure name (default) AutoGenerated) Checking "Add an omitempty label" and "Definition of Inline Type". The video is a good example of the "Cutting" and "Closing" of the "Cypriot" and "Closing" buttons. Field Name toGoName Convert to PascalCase Export Fields and Generate json:"原Keyname" label.
Type extrapolation rule (script consistent)
null→interface{}- String Query
string; Boolean.bool - Number: Integer Quantified
int64non-integer numberfloat64 - Numerical: Empty Numeric
[]interface{}; Otherwise, you can extrapolate the head element.[]T - Object: Generate a named structure; Anonymous when inline is opened
struct { ... } - OTITEMPty: Checking the label to
json:"key,omitempty"
Operational steps
- Pastes a real interface response or a point example fill.
- Fill in the root structure body name (if it is a legitimate Go marking intent, the tool will be cleaned as much as possible).
- Check the omitempty/ inline type, click "convert" as needed.
- Checks field type and embedded structure, and places a "copy code" in the item.
- Use
encoding/jsonInverse sequenced reality, manually modified as necessaryjson.Numberor pointer field.
Apply scene
- Fast-for-third-party API modelling
- Put the grab bag, JSON, backend DTO.
- Teaching demo JSON and Go type mapping
Borders and restrictions
- The type of array element is based on the first element and the isomer array may not be allowed.
- The large integer number may be de-ficient when it exceeds the JS security integer (browser JSON.parse limit).
- No check labels will be generated, no construction functions will be written or examples will be given.
- The same name structure will be as heavy as possible, and complex chart structures will still need to be manually organized.
FAQ
Convert failure hint JSON error?
Ensure that the input is valid JSON: the key must be double-quoted, not with comments and tail commas.
Why did the numbers turn to float64?
When? Number.isInteger For false time, use float64. If business requires a point decimal, change the type.
When does the interconnector type fit?
(b) When the structure is shallow and only one of the documents is anonymous; Deep nests are usually closed to generate multiple names.
Is this my JSON at the meeting?
Converts locally on browsers and is suitable for handling examples of undisclosed interfaces.
What about the underline in the field name?
user_id It becomes a export field UserId The first category of PascalCase, json tag still retains its original key name.
What about root?
If the array elements are objects, the structure is created by the first element object and is used in the slice type; Empty arrays are limited in type information.
Convert pipe lines against buttons
Left #input JSON, RIGHT. #output Out of Go. Root name in #structName(The default idea is the AutoGenerated type of editor name. Check #omitempty Add to json tab ,omitempty; Check #inlineType The object of the embedded object is written anonymously struct { ... } Inline. Main process:convert() ♪ And then you're gonna be like, "Assist, you're gonna be like, "Ass." jsonToGo / generateStruct → getGoType Inference type toGoName Converts the key to the export field. button:#btnPaste Paste, paste, paste.#btnConvert Convert、#btnCopy CopyOutput、#btnClear Clear. We're going to the status file. #status and showStatus。 Theme Switch toggleTheme It affects only appearance, not the type rule.
Type details and list of redrafts
null Change interface{}; String string; Boolean bool; Integer int64Non-integer float64; Empty array []interface{}, Non-empty-click header push []T。 Check manually after pasting a real response: whether the amount should be of a fixed point type, ID should be used string Precision loss, whether empty fields should be changed to the pointer, whether time strings should be replaced by time.Time Custom The isomer array and the field "sometimes sometimes unfull" are often not stable enough to be used when generated encoding/json Run one-way measurements and merge into the warehouse.
Failed to screen and privacy
The conversion failed mostly illegally JSON: single quotes, notes, tail commas, Python True/ False JSON.parse。 Large integers exceeding JS security integers are deformed on the side of the browser, and super-large ID suggests that you should be a string sample before you change the type. The full process is completed locally and is suitable for the example of an undisclosed interface; The public computer was emptying out of stock, avoiding the next person seeing business, JSON. This tool does not generate the verification of the tag, the construction function or the complete main, only delivering the draft of the script.