MCPcopy Create free account
hub / github.com/kataras/iris / sendJSON

Function sendJSON

_examples/dependency-injection/smart-contract/main.go:144–156  ·  view source on GitHub ↗

JSON helper to give end-user the ability to put indention chars or filtering the response, you can do that, optionally. If you'd like to see that function inside the Iris' Context itself raise a [Feature Request] issue and link this example.

(ctx iris.Context, resp interface{})

Source from the content-addressed store, hash-verified

142// JSON helper to give end-user the ability to put indention chars or filtering the response, you can do that, optionally.
143// If you'd like to see that function inside the Iris' Context itself raise a [Feature Request] issue and link this example.
144func sendJSON(ctx iris.Context, resp interface{}) (err error) {
145 indent := ctx.URLParamDefault("indent", " ")
146 // i.e [?Name == 'John Doe'].Age # to output the [age] of a user which his name is "John Doe".
147 if query := ctx.URLParam("query"); query != "" && query != "[]" {
148 resp, err = jmespath.Search(query, resp)
149 if err != nil {
150 return
151 }
152 }
153
154 err = ctx.JSON(resp, iris.JSON{Indent: indent, UnescapeHTML: true})
155 return err
156}

Callers 2

getAllUsersHandlerFunction · 0.70
getUserHandlerFunction · 0.70

Calls 3

URLParamDefaultMethod · 0.80
URLParamMethod · 0.80
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…