MySQL Shell 8.0  /  ...  /  JSON ラッピング

このページは機械翻訳したものです。

5.7.5 JSON ラッピング

MySQL Shell を外部ツールと統合するには、--json オプションを使用して、コマンドラインから MySQL Shell を起動したときのすべての MySQL Shell 出力の JSON ラッピングを制御できます。 --json オプションは、指定されている MySQL Shell セッションに対してのみ有効になります。

--json--json=pretty または --json=raw を指定すると、セッションの JSON ラッピングが有効になります。 --json=pretty を使用するか、値を指定しない場合、整形出力 JSON が生成されます。 --json=raw では、RAW JSON が生成されます。

JSON ラッピングがオンの場合、構成ファイルまたはコマンドライン (--result-format オプションまたはそのエイリアスのいずれかを使用) で resultFormat MySQL Shell 構成オプションに指定された値は無視されます。

--json=off を指定すると、セッションの JSON ラッピングがオフになります。 JSON ラッピングがオフになっているか、セッションに対してリクエストされなかった場合、結果セットは resultFormat MySQL Shell 構成オプションで指定された形式で通常どおりに出力されます。

例 5.7 プリティ印刷 JSON ラッピングを使用した MySQL Shell 出力 (--json または --json=pretty)

Press CTRL+C to copy
shell> echo "select * from world_x.city where countrycode='AUT'" | mysqlsh --json --sql --uri user@localhost:33060 or shell> echo "select * from world_x.city where countrycode='AUT'" | mysqlsh --json=pretty --sql --uri user@localhost:33060 { "hasData": true, "rows": [ { "ID": 1523, "Name": "Wien", "CountryCode": "AUT", "District": "Wien", "Info": { "Population": 1608144 } }, { "ID": 1524, "Name": "Graz", "CountryCode": "AUT", "District": "Steiermark", "Info": { "Population": 240967 } }, { "ID": 1525, "Name": "Linz", "CountryCode": "AUT", "District": "North Austria", "Info": { "Population": 188022 } }, { "ID": 1526, "Name": "Salzburg", "CountryCode": "AUT", "District": "Salzburg", "Info": { "Population": 144247 } }, { "ID": 1527, "Name": "Innsbruck", "CountryCode": "AUT", "District": "Tiroli", "Info": { "Population": 111752 } }, { "ID": 1528, "Name": "Klagenfurt", "CountryCode": "AUT", "District": "Kärnten", "Info": { "Population": 91141 } } ], "executionTime": "0.0067 sec", "affectedRowCount": 0, "affectedItemsCount": 0, "warningCount": 0, "warningsCount": 0, "warnings": [], "info": "", "autoIncrementValue": 0 }

例 5.8 RAW JSON ラップを使用した MySQL Shell 出力 (--json=raw)

Press CTRL+C to copy
shell> echo "select * from world_x.city where countrycode='AUT'" | mysqlsh --json=raw --sql --uri user@localhost:33060 {"hasData":true,"rows":[{"ID":1523,"Name":"Wien","CountryCode":"AUT","District":"Wien","Info":{"Population":1608144}},{"ID":1524,"Name":"Graz","CountryCode":"AUT","District":"Steiermark","Info":{"Population":240967}},{"ID":1525,"Name":"Linz","CountryCode":"AUT","District":"North Austria","Info":{"Population":188022}},{"ID":1526,"Name":"Salzburg","CountryCode":"AUT","District":"Salzburg","Info":{"Population":144247}},{"ID":1527,"Name":"Innsbruck","CountryCode":"AUT","District":"Tiroli","Info":{"Population":111752}},{"ID":1528,"Name":"Klagenfurt","CountryCode":"AUT","District":"Kärnten","Info":{"Population":91141}}],"executionTime":"0.0117 sec","affectedRowCount":0,"affectedItemsCount":0,"warningCount":0,"warningsCount":0,"warnings":[],"info":"","autoIncrementValue":0}