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

Function randomObjectJSONBytes

property_test.go:104–117  ·  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

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

Calls 2

randKeyFunction · 0.85
randomJSONValueFunction · 0.85

Tested by

no test coverage detected