j2s

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(s string) (string, error)

Convert returns a string that converts a JSON string into a Go structure.

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},
		"slice": ["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"`
	KebabCase interface{} `json:"kebab-case"`
	Map       J2S2        `json:"map"`
	Slice     []string    `json:"slice"`
	SnakeCase int         `json:"snake_case"`
	Title     string      `json:"title"`
}

type J2S2 struct {
	Child1 string `json:"child1"`
	Child2 int    `json:"child2"`
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL