ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

JSON2​Go

by evercyan Mac ALL

Sublime Plugin: make json string to Go struct

Labels json, urllib.parse

Details

Installs

  • Total 389
  • Win 0
  • Mac 389
  • Linux 0
Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7
Windows 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

JSON2Go


A Sublime plugin can translate JSON string to Go struct definition

Example

{
    "name": "ryan",
    "info": [
        1, 2, "3"
    ],
    "detail": {
        "age": 20,
        "height": "172cm"
    },
    "som":[
        {
            "aaa": 1,
            "bbb": 4
        },
        {
            "bbb": "2",
            "ccc": [
                {
                    "a": [
                        "what"
                    ],
                    "b": {
                        "name":"1"
                    },
                    "c":"c"
                }
            ]
        }
    ]
}

To:

type Demo struct {
    Detail struct {
        Height string `json:"height"`
        Age    int    `json:"age"`
    } `json:"detail"`
    Info []interface{} `json:"info"`
    Som  []struct {
        Ccc []struct {
            B struct {
                Name string `json:"name"`
            } `json:"b"`
            C string   `json:"c"`
            A []string `json:"a"`
        } `json:"ccc"`
        Bbb interface{} `json:"bbb"`
        Aaa int         `json:"aaa"`
    } `json:"som"`
    Name string `json:"name"`
}

Install


  • Manual
MacOs:
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
git clone https://github.com/everCyan/JSON2Go
  • Sublime Plugin
Package Control: Install Package
input `JSON2GO`

Menu

right click, the menu like this:
- JSON2Go

    - JSON2Go       translate JSON string to Go struct

    - ToUpper       translate to upper
    - ToLower       translate to lower

    - JsonExpand    translate one line json string to BASIC json struct
    - JsonShrink    translate json struct to one line json string

    - StrEscape     escape str
    - StrUnescape   unescape str

    - UrlEncode     encode url
    - UrlDecode     decode url

Help (JSON2Go js): https://github.com/mholt/json-to-go