jgoson

package module
v0.0.0-...-26ac8bb Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 7 Imported by: 0

README

jgoson

This is a simple app that generates Golang code from JSON. It can generate inlined structs as well as separate structs.

Installation

go install github.com/knightpp/jgoson/cmd/jgoson@latest

or with Nix flakes

nix profile install github:knightpp/jgoson

How to use

cat example.json | jgoson -inline=true -tag=yaml -tag-opts="a,b,c"

Known issues

  • Does not generate unique struct names for nested structs

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LowerCamelCaseToSnakeCase

func LowerCamelCaseToSnakeCase(name string) string

func SnakeCaseToUpperCamelCase

func SnakeCaseToUpperCamelCase(name string) string

Types

type Config

type Config struct {
	Tag       string
	TagNameFn func(fieldName string) string
	TagOpts   []string

	StructNameFn  func(structName string) string
	StructFieldFn func(fieldName string) string
}

func (*Config) FillDefaults

func (c *Config) FillDefaults()

type Field

type Field struct {
	Name string `json:"name,omitempty"`
	Type *Type  `json:"type,omitempty"`
}

Field represents a field in a struct.

type Type

type Type struct {
	Name    string  `json:"name,omitempty"`
	Fields  []Field `json:"fields,omitempty"`
	IsSlice bool    `json:"is_slice,omitempty"`
}

Type represents a type in Go.

func Parse

func Parse(value map[string]any) *Type

func ParseJSON

func ParseJSON(r io.Reader) (*Type, error)

func (*Type) IsStruct

func (t *Type) IsStruct() bool

func (*Type) ToGo

func (t *Type) ToGo(w io.Writer, cfg Config)

ToGo generates Go code for the given type using the provided config, but the types are not inlined.

func (*Type) ToGoInline

func (t *Type) ToGoInline(w io.Writer, cfg Config)

ToGoInline generates Go code for the given type using the provided config, and the types are inlined.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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