 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶
Convert uses the default options and returns a string of JSON strings converted to Go structures.
The default values are as follows.
Option {
    UseTag:    true,
    TagName:   "json",
    Omitempty: OmitemptyNone,
}
return an error if the string is invalid as JSON.
Example ¶
package main
import (
	"fmt"
	"github.com/masakurapa/go-json2struct/pkg/j2s"
)
func main() {
	input := `{
		"title": "j2s",
		"snake_case": 99,
		"CamelCase": true,
		"kebab-case": null,
		"map": {"child1": "apple", "child2": 12345},
		"array": ["1", "2", "3", "4", "5"]
	}`
	output, err := j2s.Convert(input)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(output)
}
Output: type J2S1 struct { CamelCase bool `json:"CamelCase"` Array []string `json:"array"` KebabCase interface{} `json:"kebab-case"` Map J2S2 `json:"map"` SnakeCase int `json:"snake_case"` Title string `json:"title"` } type J2S2 struct { Child1 string `json:"child1"` Child2 int `json:"child2"` }
Types ¶
type Omitempty ¶ added in v0.3.0
type Omitempty int
Omitempty is an optional type that outputs "omitempty"
type Option ¶ added in v0.3.0
type Option struct {
	// UseTag outputs tag if true
	UseTag bool
	// TagName is a tag name. (default is "json")
	//
	// if empty, the default value is used.
	//
	// if "UseTag" is false, the value is not used.
	TagName string
	// Omitempty is an optional type that outputs "omitempty". (default is non output)
	Omitempty Omitempty
}
    Option is an option to customize output results
 Click to show internal directories. 
   Click to hide internal directories.