Giter VIP home page Giter VIP logo

json's Introduction

permalink sidebarBasedOnContent
/
true

xjson

import "github.com/goclub/json"

Go JSON standard package extension library.

Go 官方 JSON 标准库扩展

Extension feature

扩展特性

  1. nil slice nad nil map marshal to [] or {} instead of null.
  1. 空切片空 map 序列化字符串为 []{} 而不是 null
response := struct {
    Books []string `json:"books"`
    Map map[string]string `json:"map"`
}{}
data, err := xjson.Marshal(response) ; if err != nil {panic(err)}
log.Print(string(data)) // {"books":[], map:{}}
  1. auto int and float convert to stirng instead return error.

自动int和 float到字符串,而不是返回错误

request := struct {
    Page int `json:"page"`
    Price float64 `json:"price"`
}{}
err := xjson.Unmarshal([]byte(`{"page":"1", "price": "1.05"}`), &request) ; if err != nil {panic(err)}
log.Printf("%+v", request) // {Page:1 Price:1.05}
request := struct {
   ID string `json:"id"`
}{}
err := xjson.Unmarshal([]byte(`{"id":1`), &request) ; if err != nil {panic(err)}
log.Printf("%+v", request) // {ID:"1"}

json's People

Contributors

nimoc avatar

Watchers

 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.