move json encoding to after jsoncallback handling