jsonfield

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

jsonfield

A json marshaller by supporting fields.

doc

Documentation

Overview

Example
package main

import (
	"github.com/mnhkahn/gogogo/logger"
	"github.com/mnhkahn/jsonfield"
)

type A struct {
	A int
	B int
}

func main() {
	jj := new(A)
	jj.A, jj.B = 111, 222

	buf, _ := jsonfield.Marshal(jj)
	logger.Info(string(buf)) // prints {"A":111,"B":222}

	buf, _ = jsonfield.Marshal(jj, "A")
	logger.Info(string(buf)) // prints {"A":111}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}, fields ...string) ([]byte, error)

Marshal is compatible with std json.Marshal. If fields is nil it acts as the std json package. If fields is not nil it will only return the provided fields.

Example
package main

import (
	"github.com/mnhkahn/jsonfield"
)

type A struct {
	A int
	B int
}

func main() {
	jj := new(A)
	jj.A, jj.B = 111, 222
	byts, err := jsonfield.Marshal(jj, "A") // {"A":111}
	_, _ = byts, err
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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