Documentation Home
MySQL Shell 8.0
Related Documentation Download this Manual
PDF (US Ltr) - 376.7Kb
PDF (A4) - 371.1Kb
HTML Download (TGZ) - 74.8Kb
HTML Download (Zip) - 86.6Kb


MySQL Shell 8.0  /  ...  /  JSON Wrapping

5.6.5 JSON Wrapping

To help integrate MySQL Shell with external tools, you can use the --json option to control JSON wrapping for all MySQL Shell output when you start MySQL Shell from the command line. The --json option only takes effect for the MySQL Shell session for which it is specified.

Specifying --json, --json=pretty, or --json=raw turns on JSON wrapping for the session. With --json=pretty or with no value specified, pretty-printed JSON is generated. With --json=raw, raw JSON is generated.

When JSON wrapping is turned on, any value that was specified for the resultFormat MySQL Shell configuration option in the configuration file or on the command line (with the --result-format option or one of its aliases) is ignored.

Specifying --json=off turns off JSON wrapping for the session. When JSON wrapping is turned off, or was not requested for the session, result sets are output as normal in the format specified by the resultFormat MySQL Shell configuration option.

MySQL Shell Output with JSON Wrapping

shell>echo "select * from sakila.actor limit 3;" | mysqlsh --json=raw --sqlc --uri user@192.0.2.20:3306
{"duration":"0.00 sec","info":"","row_count":3,"rows":[[1,"PENELOPE","GUINESS",{"year":2006,"month":1,"day":15,"hour":4,"minute":34,"second":33.0}],[2,"NICK","WAHLBERG",{"year":2006,"month":1,"day":15,"hour":4,"minute":34,"second":33.0}],[3,"ED","CHASE",{"year":2006,"month":1,"day":15,"hour":4,"minute":34,"second":33.0}]],"warning_count":0}

shell>echo "select * from sakila.actor limit 3;" | mysqlsh --json --sqlc --uri user@192.0.2.20:3306
or
shell>echo "select * from sakila.actor limit 3;" | mysqlsh --json=pretty --sqlc --uri user@192.0.2.20:3306
{
    "duration": "0.00 sec",
    "info": "",
    "row_count": 3,
    "rows": [
        [
            1,
            "PENELOPE",
            "GUINESS",
            {
                "year": 2006,
                "month": 1,
                "day": 15,
                "hour": 4,
                "minute": 34,
                "second": 33.0
            }
        ],
        [
            2,
            "NICK",
            "WAHLBERG",
            {
                "year": 2006,
                "month": 1,
                "day": 15,
                "hour": 4,
                "minute": 34,
                "second": 33.0
            }
        ],
        [
            3,
            "ED",
            "CHASE",
            {
                "year": 2006,
                "month": 1,
                "day": 15,
                "hour": 4,
                "minute": 34,
                "second": 33.0
            }
        ]
    ],
    "warning_count": 0
}
shell>