0

I am exporting a part of MySQL Database as JSON Format. I want to do this from mysql-cli without using any web interfaces like phpmyadmin or softwares like mysqlworkbench.

I am aware that I can do so by using php json_encode() function after a mysql query.

But are there any methods that can be used, so that I can write a mysql query to get the dump as JSON.

I used php to do this.

json_encode($result);
Stefan Becker
  • 5,695
  • 9
  • 20
  • 30
  • What version of MySQL are you using? – Nick Feb 07 '19 at 06:15
  • you can use `JSON_ARRAY` OR `JSON_OBJECT` – Devsi Odedra Feb 07 '19 at 06:16
  • 2
    Go through these link might it helps you: [https://stackoverflow.com/questions/41758870/how-to-convert-result-table-to-json-array-in-mysql](https://stackoverflow.com/questions/41758870/how-to-convert-result-table-to-json-array-in-mysql) –  Feb 07 '19 at 06:18

1 Answers1

0

From mysql version 5.7.8 you can use JSON_ARRAY, JSON_OBJECT to converting query output as json. Here is many more in mysql official documentation: https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html