MCPcopy Create free account
hub / github.com/prometheus/common / MarshalJSON

Method MarshalJSON

model/value.go:74–99  ·  view source on GitHub ↗

MarshalJSON implements json.Marshaler.

()

Source from the content-addressed store, hash-verified

72
73// MarshalJSON implements json.Marshaler.
74func (s Sample) MarshalJSON() ([]byte, error) {
75 if s.Histogram != nil {
76 v := struct {
77 Metric Metric `json:"metric"`
78 Histogram SampleHistogramPair `json:"histogram"`
79 }{
80 Metric: s.Metric,
81 Histogram: SampleHistogramPair{
82 Timestamp: s.Timestamp,
83 Histogram: s.Histogram,
84 },
85 }
86 return json.Marshal(&v)
87 }
88 v := struct {
89 Metric Metric `json:"metric"`
90 Value SamplePair `json:"value"`
91 }{
92 Metric: s.Metric,
93 Value: SamplePair{
94 Timestamp: s.Timestamp,
95 Value: s.Value,
96 },
97 }
98 return json.Marshal(&v)
99}
100
101// UnmarshalJSON implements json.Unmarshaler.
102func (s *Sample) UnmarshalJSON(b []byte) error {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected