youbbs avatar

Golang 版 json to go

🕥 by youbbs

Caddy 的作者 Matt Holt 用 js 写了一个小工具 json to go 可以方便的把 json 字符串转为go struct

现在好事者就用 go 来实现相同的转换功能

Go: json-to-go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import (
    "github.com/kumakichi/json-to-go"
)

func main() {
    println(json_to_go.Parse(testData))
    println(json_to_go.Parse(testData, json_to_go.Options{TypeName: "rootName", Flatten: true}))
}

var (
    testData = `{
    "name": {"first": "Tom", "last": "Anderson"},
    "age":37,
    "score": 92.0,
    "children": ["Sara","Alex","Jack"],
    "friends": [
      {"first": "James", "last": "Murphy"},
      {"first": "Roger", "last": "Craig"}
    ]
  }`
)

还其它很有用的工具

💘 相关文章

写一条评论

Based on Golang + fastHTTP + sdb | go1.16.3 Processed in 1ms