JSONをCSVに変換してExcelで開く方法
- 選ぶ
- 貼る
- 保存する
APIなどから受け取ったJSONのデータを、Excelで開いて、並べ替えたり集計したりしたい。CSVとJSONを相互変換する で、JSONをCSVに変換できます。
手順(JSON → CSV)
- 「変換の向き」で、「JSON → CSV」を選びます。
- 「区切り文字(CSV)」を選びます。Excelで開くなら、「カンマ」がおすすめです。
- 「変換前」に、JSONを貼り付けます。
- 「変換する」を押します。
- 「変換後」に、CSVが出ます。「ファイルで保存」で、ファイルにします。
- 保存したファイルを、Excelで開きます。
変換できるJSONの形
同じ項目を持つデータが、並んだ形が向いています。
例:「名前」と「年齢」を持つデータが、複数件並んでいる。
このような形なら、1件が1行、項目名が見出しになります。
Excelで開くときのコツ
- 保存したファイルをダブルクリックしても、文字化けする場合がある。
- 文字化けするときは、Excelの「データ」メニューから、「テキストまたはCSVから」で読み込むと、文字コードを指定できる。
- 区切り文字をタブにして、そのまま貼り付ける方法もある。
貼り付けて使う方法
「結果をコピー」でコピーして、Excelのセルに貼り付けると、1つのセルに入ってしまうことがあります。そのときは、Excelの「区切り位置」機能を使います。タブ区切りで変換すれば、そのまま列に分かれて貼り付けられます。
向いている場面
- APIの結果を、表で確認する
- アクセスログや、設定データを、集計する
- 別のシステムからの出力を、Excelで見る
例
WebサービスのAPIが返したJSONを、Excelで集計したかった。JSONを貼り付けて「JSON → CSV」に変換。保存したファイルをExcelで開いて、グラフを作った。
つまずきやすい点
- 入れ子のJSONが、1つのセルに入る:別の解説を参照。
- 項目が揃っていないデータ:行によって、列が足りないことがある。
- 数値が文字として扱われる:Excel側で、書式を設定する。
よくある質問
日本語は文字化けしませんか?
ファイルを開く側の設定によります。文字化けするときは、文字コードを指定して読み込みます。
まとめ
JSONを貼り付けて変換し、ファイルにしてExcelで開く。文字化けには、読み込みの設定で対応します。
CSVとJSONを相互変換するを使う(無料)あわせて使えるツール
- 重複した行を消す・並べ替える:重複した行を消して、並べ替えます。
- ファイルをZIPにまとめる:複数のファイルを、1つのZIPにまとめます。
- 文字数カウント(エントリーシート・レポート用):文章の文字数・行数・原稿用紙の枚数などを数えます。
同じツールの、ほかの解説
How to Convert JSON to CSV and Open It in Excel
- Choose
- Paste
- Save
You want to open JSON data received from an API or similar in Excel, to sort or total it. Convert CSV and JSON can convert JSON to CSV.
Steps (JSON → CSV)
- For "Direction", choose "JSON → CSV".
- Choose the "Delimiter (CSV)". For opening in Excel, "comma" is recommended.
- Paste the JSON into "Before conversion".
- Press "Convert".
- The CSV appears under "After conversion". Make it a file with "Save as file".
- Open the saved file in Excel.
The JSON shapes that can be converted
A form where data with the same items is lined up suits it.
Example: several records each with a "name" and "age".
In such a form, one record becomes one row and the item names become headings.
Tips for opening in Excel
- Double-clicking the saved file may garble the text.
- If garbled, import via Excel's "Data" menu, "From Text/CSV", where you can specify the encoding.
- Another way is to set the delimiter to tab and paste as is.
Using paste
Copying with "Copy result" and pasting into an Excel cell may put everything in one cell. In that case use Excel's "Text to Columns". If converted with tab as the delimiter, it pastes straight into columns.
Good for
- Viewing API results as a table
- Totalling access logs and configuration data
- Viewing output from another system in Excel
Example
Wanted to total JSON returned by a web service's API in Excel. Pasted the JSON and converted with "JSON → CSV". Opened the saved file in Excel and made a chart.
Common stumbling blocks
- Nested JSON goes into one cell: see the separate guide.
- Data with uneven items: some rows may lack columns.
- Numbers treated as text: set the format on the Excel side.
Frequently asked questions
Won't Japanese be garbled?
It depends on the settings of the side opening the file. If garbled, import specifying the encoding.
Summary
Paste JSON, convert, save as a file and open in Excel. Handle garbling through the import settings.
Use "Convert CSV and JSON" (free)Tools that go well with this
- Remove Duplicate Lines and Sort a List: Remove duplicate lines and sort them.
- Make a ZIP File: Pack several files into one ZIP.
- Character Counter (for Applications and Reports): Count characters, lines and manuscript sheets of your text.