GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — go-lytics/json_test.go at master · lytics/go-lytics

Expand file tree

/

json_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (60 loc) · 1.78 KB
/

json_test.go

Copy path

File metadata and controls

65 lines (60 loc) · 1.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
58
59
60
61
62
63
64
65
package lytics
import (
"encoding/json"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestJsonFlatten(t *testing.T) {
msg := `{
"reach":4,
"source":"http://twitter.com/tweetbutton",
"tweet_id":"302601869862252544",
"bigint":7000000000000000000000,
"twuser_id":"829488326",
"twuser_location":"",
"twuser_screenname":"maranda_hampton",
"url":["https://www.athletepath.com/join"],
"nested": {
"a": [
{
"b": {
"c": [
[
{
"d": "1"
}
]
]
}
}
]
},
"heterogeneousList": ["a", 3.14],
"hasNullVal": null
}`
flat, err := FlattenJson([]byte(msg))
assert.Equal(t, nil, err)
assert.Equal(t, 1, len(flat["reach"]))
assert.Equal(t, "4", flat["reach"][0])
assert.Equal(t, "http://twitter.com/tweetbutton", flat["source"][0])
assert.Equal(t, "302601869862252544", flat["tweet_id"][0])
assert.Equal(t, "829488326", flat["twuser_id"][0])
assert.Equal(t, "7000000000000000000000", flat["bigint"][0])
assert.Equal(t, "", flat["twuser_location"][0])
assert.Equal(t, "maranda_hampton", flat["twuser_screenname"][0])
assert.Equal(t, "https://www.athletepath.com/join", flat["url"][0])
assert.Equal(t, "1", flat["nested.a[0].b.c[0][0].d"][0])
assert.Equal(t, "a", flat["heterogeneousList"][0])
assert.Equal(t, "3.14", flat["heterogeneousList"][1])
_, ok := flat["hasNullVal"]
assert.Equal(t, true, ok)
assert.Equal(t, 0, len(flat["hasNullVal"]))
var jsonMap map[string]interface{}
err = json.Unmarshal([]byte(msg), &jsonMap)
assert.Truef(t, err == nil, "must not err: %v", err)
qs := make(url.Values)
err = FlattenJsonMapIntoQs(qs, jsonMap, "")
assert.Truef(t, err == nil, "must not err: %v", err)
assert.Truef(t, qs.Get("bigint") == "7000000000000000000000", "must not have exponent format")
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.