Skip to content

this is a go json tool like encode/json but allow you to use camel and underScore name style

License

Notifications You must be signed in to change notification settings

JessonChan/jsun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}

About

this is a go json tool like encode/json but allow you to use camel and underScore name style

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages