MCPcopy Index your code
hub / github.com/gavv/httpexpect / JSON

Method JSON

response.go:872–893  ·  view source on GitHub ↗

JSON returns a new Value instance with JSON decoded from response body. JSON succeeds if response contains "application/json" Content-Type header with empty or "utf-8" charset and if JSON may be decoded from response body. Example: resp := NewResponse(t, response) resp.JSON().Array().ConsistsOf

(options ...ContentOpts)

Source from the content-addressed store, hash-verified

870// MediaType: "application/json",
871// }).Array.ConsistsOf("foo", "bar")
872func (r *Response) JSON(options ...ContentOpts) *Value {
873 opChain := r.chain.enter("JSON()")
874 defer opChain.leave()
875
876 if opChain.failed() {
877 return newValue(opChain, nil)
878 }
879
880 if len(options) > 1 {
881 opChain.fail(AssertionFailure{
882 Type: AssertUsage,
883 Errors: []error{
884 errors.New("unexpected multiple options arguments"),
885 },
886 })
887 return newValue(opChain, nil)
888 }
889
890 value := r.getJSON(opChain, "JSON()", options...)
891
892 return newValue(opChain, value)
893}
894
895func (r *Response) getJSON(
896 opChain *chain, method string, options ...ContentOpts,

Callers 15

TestResponse_JSONFunction · 0.95
TestResponse_ContentOptsFunction · 0.95
TestResponse_ReaderFunction · 0.95
TestResponse_UsageFunction · 0.95
TestResponse_FailedChainFunction · 0.45
TestResponse_NoContentFunction · 0.45
TestExpect_TraverseFunction · 0.45
TestExpect_BranchesFunction · 0.45
TestExpect_InheritanceFunction · 0.45
TestFailureTemplateFunction · 0.45

Calls 6

getJSONMethod · 0.95
newValueFunction · 0.85
enterMethod · 0.80
leaveMethod · 0.80
failedMethod · 0.80
failMethod · 0.80

Tested by 15

TestResponse_JSONFunction · 0.76
TestResponse_ContentOptsFunction · 0.76
TestResponse_ReaderFunction · 0.76
TestResponse_UsageFunction · 0.76
TestResponse_FailedChainFunction · 0.36
TestResponse_NoContentFunction · 0.36
TestExpect_TraverseFunction · 0.36
TestExpect_BranchesFunction · 0.36
TestExpect_InheritanceFunction · 0.36
TestFailureTemplateFunction · 0.36