Jsonpack compress, shorten json volume for in Golang

Description

A compression algorithm for JSON

gjsonpack is a GoLang program to pack and unpack JSON data.

It can compress to 55% of original size if the data has a recursive structure.

take JavaScript transformation to GoLang, source repositories please see.

Repositories URL

github: https://github.com/JoiLa/gjsonpack/

How to use?

go get github.com/JoiLa/gjsonpack

How to usHow to compress json

// big JSON
var basicJSON = `{
    "type": "world",
    "name": "earth",
    "children": [
        {
            "type": "continent",
            "name": "America",
            "children": [
                {
                    "type": "country",
                    "name": "Chile",
                    "children": [
                        {
                            "type": "commune",
                            "name": "Antofagasta"
                        }
                    ]
                }
            ]
        },
        {
            "type": "continent",
            "name": "Europe"
        }
    ]
}`

jsonMap := make(map[string]interface{}, 0)
if err := json.Unmarshal([]byte(basicJSON), &jsonMap); err != nil {
    t.Fatal(err)
}

// pack the big JSON 
packStr, packErr := Pack(jsonMap)
if packErr != nil {
    fmt.Fprintln(packErr)
}
fmt.Println("packStr:", packStr)
// packStr: type|world|name|earth|children|continent|America|country|Chile|commune|Antofagasta|Europe^^^$0|1|2|3|4|@$0|5|2|6|4|@$0|7|2|8|4|@$0|9|2|A]]]]]|$0|5|2|B]]]

// do something with the packed JSON

How to decompress json

packStr:="type|world|name|earth|children|continent|America|country|Chile|commune|Antofagasta|Europe^^^$0|1|2|3|4|@$0|5|2|6|4|@$0|7|2|8|4|@$0|9|2|A]]]]]|$0|5|2|B]]]"
jsonMap := make(map[string]interface{}, 0)
unPackErr := Unpack(packStr, &jsonMap)
if unPackErr != nil {
    return
}
fmt.Printf("jsonMap:%v\n", jsonMap)
// jsonMap:map[children:[map[children:[map[children:[map[name:Antofagasta type:commune]] name:Chile type:country]] name:America type:continent] map[name:Europe type:continent]] name:earth type:world]

// do something with the unPacked JSON

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇