jsun

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 3 Imported by: 1

README

jsun

this is a go json tool like encode/json but allow you to use camelName/CamelName or under_score name style

package main

import (
	"fmt"

	"github.com/JessonChan/jsun"
)

type Person struct {
	Id        int
	FirstName string
	LastName  string `json:"name"`
}

func main() {
	p := Person{
		Id:        1,
		FirstName: "FirstName",
		LastName:  "LastName",
	}
	b, _ := jsun.Marshal(p)
    // or
	// b, _ := jsun.Marshal(p,jsun.LowerCamelStyle)
	fmt.Println(string(b))
}

output

{"id":1,"firstName":"FirstName","name":"LastName"}

package main

import (
	"fmt"

	"github.com/JessonChan/jsun"
)

type Person struct {
	Id        int
	FirstName string
	LastName  string `json:"name"`
}

func main() {
	p := Person{
		Id:        1,
		FirstName: "FirstName",
		LastName:  "LastName",
	}
	b, _ := jsun.Marshal(p, jsun.UnderScoreStyle)
	fmt.Println(string(b))
}

output

{"id":1,"first_name":"FirstName","name":"LastName"}

package main

import (
	"fmt"

	"github.com/JessonChan/jsun"
)

type Person struct {
	Id        int
	FirstName string
	LastName  string `json:"name"`
}

func main() {
	p := Person{
		Id:        1,
		FirstName: "FirstName",
		LastName:  "LastName",
	}
	b, _ := jsun.Marshal(p, jsun.UpperCamelStyle)
	fmt.Println(string(b))
}

output

{"id":1,"FirstName":"FirstName","name":"LastName"}

Documentation

Index

Constants

View Source
const (
	LowerCamelStyle = JsonNameStyle(0)
	UpperCamelStyle = JsonNameStyle(1)
	UnderScoreStyle = JsonNameStyle(2)
)

Variables

View Source
var DebugMessage bool

Functions

func Marshal

func Marshal(v interface{}, styles ...JsonNameStyle) ([]byte, error)

func SetDefaultStyle added in v0.0.2

func SetDefaultStyle(style JsonNameStyle)

Types

type JsonNameStyle added in v0.0.2

type JsonNameStyle int

Directories

Path Synopsis
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.

Jump to

Keyboard shortcuts

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