Shikloshi Shikloshi - 1 year ago 124
JSON Question

Print function that consumes json.RawMessage directly

I'm doing some work with

and the query return a
object which it's type is

I only want to print it to screen without creating struct model for it and doing the obvious

Is there a print function that will consume *json.RawMessage type and print it to screen?

Code sample:

for _, hit := range serachResult.Hits.Hits {
fmt.Println(hit.Source, "\n")

This code run will result in un-readable array of bytes, apparently without the ability to just build a
from the raw message.

Answer Source

You can use %s to printf:

for _, hit := range serachResult.Hits.Hits {
   fmt.Printf("%s\n", hit.Source)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download