Giter Club home page Giter Club logo

json-to-go's Introduction

json-to-go

将json生成go的数据结构。Online tool that convert JSON to Go.

Online Link | 地址

Local Develope | 本地开发

suggest use(强烈建议使用) pnpm !!!

  • install pnpm install

  • dev pnpm dev

  • build pnpm build

custom tag | 自定义tag

  • format | 格式
<tag name>:[name method]:[is add omitempty]
<tag名字>:[命名方式]:[是否添加omitempty]
  • name method | 命名方式
  1. original | 原样返回
  2. abcDef | 小驼峰 - 默认
  3. AbcDef | 大驼峰
  4. abc_def | 下划线
  5. Abcdef | 只有第一个字母大写
  6. abcdef | 全都小写
  • examples | 例子

json

form

json:1:true

json:3:false,form:2:true,query:1:false

Features | 特征

  • custom tag | 支持自定义tag
  • custom root object name | 支持自定义根对象名
  • support inline | 支持内联结构
  • support edit | 支持编辑
  • json syntax extension | 对json语法进行了扩展,支持不规范的json
  • json check/format/compress | 支持不规范的json的纠正、格式化、压缩

Reference | 参考

json-to-go's People

Contributors

lhlyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

json-to-go's Issues

结构相同问题

  • 同结构,属性类型不同
{
    "aaa": {
        "bbb": {
            "a": 123
        }
    },
    "bbb": {
        "a": true
    }
}
  • 同结构,属性不同
{
    "aaa": {
        "bbb": {
            "a": 123
        }
    },
    "bbb": {
        "b": true
    }
}
  • 深层次嵌套同结构

对于key是数字类型的转换思考

{
    "a": -1231.323,
    "b": {
        "z": 31,
        "p": true,
        "123": "key是字符串"
    }
}

下面哪种转换比较合理呢......

type RootObject struct {
    A float64                `json:"a"`
    B map[string]interface{} `json:"b"`
}
type RootObject struct {
    A float64 `json:"a"`
    B B       `json:"b"`
}
type B struct {
    Z           int    `json:"z"`
    P           bool   `json:"p"`
    NumberField string `json:"123"`
}

[BUG]多维数组转换错误

Original Data

{
    "a": 123,
    "b": "xxx",
    "c": [
        [
            1,
            2,
            3
        ],
        [
            1,
            null,
            3
        ]
    ]
}

Result

type RootObject struct {
    A int           `json:"a"`
    B string        `json:"b"`
    C []interface{} `json:"c"`
}

Expect

type RootObject struct {
    A int           `json:"a"`
    B string        `json:"b"`
    C [][]interface{} `json:"c"`
}

根据整数范围限制对映射类型做调整

const (
	MaxInt8   = 1<<7 - 1
	MinInt8   = -1 << 7
	MaxInt16  = 1<<15 - 1
	MinInt16  = -1 << 15
	MaxInt32  = 1<<31 - 1
	MinInt32  = -1 << 31
	MaxInt64  = 1<<63 - 1
	MinInt64  = -1 << 63
	MaxUint8  = 1<<8 - 1
	MaxUint16 = 1<<16 - 1
	MaxUint32 = 1<<32 - 1
	MaxUint64 = 1<<64 - 1
)

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.