Coder Social home page Coder Social logo

zjson's Introduction

zjson

json friendly string builder. it from uber zap package.

change:

  • add RawMessage Field Type

note:

  • default every row have LineEnding '\n' , but you can intervene through configuration

example:

package main

import (
	"log"
	"time"

	"github.com/zplzpl/zjson"
)

func main() {
	encoder := zjson.NewJSONEncoder(zjson.NewProductionEncoderConfig())

	buf, err := encoder.Encode(
		zjson.String("A", "test1"),
		zjson.Time("B", time.Now()),
		zjson.String("C", "test2"),
		zjson.Int64("D", 100),
		zjson.RawMessage("E", []byte(`{}`)),
	)

	if err != nil {
		log.Fatal(err.Error())
	}

	log.Println(string(buf.Bytes()))
}

output:

{"A":"test1","B":"2020-02-10T22:46:14+08:00","C":"test2","D":100,"E":{}}

中文说明

这是个友好的json字符串构造器,从uber zap包中提出出来。

用途:

  • 用json输出某些简短的数据时候,又有性能要求的时候,用这个简单快捷

变动:

  • 增加RawMessage的字段类型

注意:

  • 目前输出默认追加"\n"符号

zjson's People

Contributors

zplzpl avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.