Json encode for sql results