unrolled/render

Passing a string containing JSON to render.JSON()

flexd opened this issue · 3 comments

Hi.

Would it be possible to add a check in engine.Render to not marshal already marshaled JSON?
The reason this would be useful is for example when/if something has been marshaled and stored to a cache or a key-value store like Redis. The data coming out of Redis (in my case) is already JSON, so I would have to unmarshal the data and then have render.JSON re-marshal it.

Does that make sense?

I understand what you mean, but I don't think this belongs in render. I can't think of a clean quick solution that wouldn't impact performance for everything other user using the render package. If it were me, I would do something like this:

if dataCameFromRedis {
    rw.Header().Set("Content-Type", "application/json")
    fmt.Fprint(rw, jsonStringFromRedis)
    return
}
// otherwise, carry on as you would normally.

Does this help?

Yeah sure, I knew I could do that. It just makes sense for me if Render had an option for this. But I understand you do not want to make it any slower than it needs to be.

What I mean by that is: "it makes sense" === "i am lazier than it appears" 👍