-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdoc.go
More file actions
57 lines (40 loc) · 1.4 KB
/
doc.go
File metadata and controls
57 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2012 The jflect Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Jflect takes JSON from stdin and outputs go structs to stdout.
Installing
go get github.com/str1ngs/jflect
Examples
Web service:
curl https://api.github.com/users/str1ngs | jflect -s GithubUser
Output:
type GitHubUser struct {
AvatarUrl string `json:"avatar_url"`
Bio string `json:"bio"`
CreatedAt string `json:"created_at"`
Followers int `json:"followers"`
Following int `json:"following"`
GravatarId string `json:"gravatar_id"`
Hireable bool `json:"hireable"`
HtmlUrl string `json:"html_url"`
Id int `json:"id"`
Location string `json:"location"`
Login string `json:"login"`
Name string `json:"name"`
PublicGists int `json:"public_gists"`
PublicRepos int `json:"public_repos"`
Type string `json:"type"`
Url string `json:"url"`
}
From file:
jflect < foo.json
Saving is just a matter of redirecting stdout to a file.
jflect < foo.json > foo.go
curl https://api.github.com/users/str1ngs | jflect -s GihubUser > gituser.go
Notes
Jflect is primarily designed to fast prototype go structs. Its not intended for
automation. It does handle nested JSON objects. But does not currently handle
arbitrary JSON arrays.
*/
package main