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
Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13 Jun 12
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