I must option to output the data in database (Mysql) to become json format.

  1. directly connect with database and fetch the information and output json
  2. connect with a Relaxation service to obtain the data and output json.

What's best and why?

directly connect with database and fetch the information and output json

If you're hooking up towards the database (does not matter whether it's MySQL or something like that else) directly through binary based protocol it ought to be faster than Relaxation based protocol.

connect with a Relaxation service to obtain the data and output json.

Relaxation based methods are however simpler, straightforward and simpler to implement in the client side of view than binary ones generally.

What's best and why?

It is dependent if you want speed or convenience. Just in case of binary connection you'd additionaly need to parse fetched data to JSON. Relaxation service can provide you with usually just the thing you need in preferred JSON format. If however speed is vital for you personally then binary protocol is much better choice I'd say.