Struct to JSON Generator
This Visual Studio Code extension converts Go structs to JSON format with realistic fake data, offering a powerful tool for testing and development.
Features
- Converts selected Go struct to JSON with fake data
- Generates multiple JSON objects based on the same struct
- Supports nested structs and various Go types including slices
- Intelligently generates fake data based on field names (e.g., email, name, ID)
- Copies the generated JSON to clipboard
- Offers pretty-printing of JSON output
- Customizable number of JSON objects to generate
Requirements
- Visual Studio Code 1.6.0 or higher
- Go must be installed on your system
Installation
- Open Visual Studio Code
- Press
Ctrl+P (or Cmd+P on macOS) to open the Quick Open dialog
- Type
ext install your-publisher-name.struct-to-json-generator and press Enter
Usage
- Open a Go file containing the struct you want to convert
- Select the entire struct in your editor
- Open the Command Palette (
Ctrl+Shift+P or Cmd+Shift+P on macOS)
- Type "Generate JSON from Struct" and select the command
- The generated JSON will be copied to your clipboard and a notification will appear
Supported Types
The extension supports the following Go types:
- Basic types: string, int, int32, int64, bool, float64
- Time: time.Time
- Custom types: decimal.Decimal
- Slices of supported types
- Nested structs
Fake Data Generation
The extension generates realistic fake data based on field names:
- Fields containing "id" generate UUIDs
- Fields containing "name" generate full names
- Fields containing "email" generate email addresses
- Fields containing "country" generate country names
- Fields containing "currency" generate currency codes
- Fields containing "datetime" generate RFC3339 formatted dates
- Fields containing "status" generate random statuses
- Fields containing "password" generate secure passwords
Other string fields generate sentences, and numeric fields generate random numbers within a reasonable range.
Known Issues
Please report any issues on the GitHub repository.
Release Notes
0.0.1
Initial release of Struct to JSON Generator
Enjoy!
| |