Sounds like the problem now is with building the output. I assume that code has changed some since your original post, as you’re now looking at profile names where before it wasn’t. debug($results)
will just show you the Query object, but debug($results->toArray())
will be the actual records, and should shed some light on how you need to go about creating your JSON array.