MCPcopy Create free account
hub / github.com/buger/jsonparser / randomObjectJSONBytes

Function randomObjectJSONBytes

property_test.go:105–118  ·  view source on GitHub ↗

randomObjectJSONBytes returns marshaled JSON for a random top-level object along with the map so tests can predict values.

(r *mathrand.Rand, depth int)

Source from the content-addressed store, hash-verified

103// randomObjectJSONBytes returns marshaled JSON for a random top-level object
104// along with the map so tests can predict values.
105func randomObjectJSONBytes(r *mathrand.Rand, depth int) ([]byte, map[string]interface{}) {
106 n := r.Intn(4) + 1
107 obj := make(map[string]interface{}, n)
108 for i := 0; i < n; i++ {
109 obj[randKey(r)] = randomJSONValue(r, depth)
110 }
111 b, err := json.Marshal(obj)
112 if err != nil {
113 // The generator must only emit json.Marshal-able values; if not, fall
114 // back to a trivial object so the property stays well-defined.
115 return []byte(`{}`), map[string]interface{}{}
116 }
117 return b, obj
118}
119
120// randomJSONBytes returns marshaled JSON for any random value.
121func randomJSONBytes(r *mathrand.Rand, depth int) []byte {

Calls 2

randKeyFunction · 0.85
randomJSONValueFunction · 0.85

Tested by

no test coverage detected