0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JsonをCSVに変換する Mac版

Last updated at Posted at 2022-12-22

「jsonファイルをcsvに変換したいな!」ってことがあったので、備忘録です。

環境

Homebrewが必要。
Mac OSは12.6で事前にHomebrewがインストールされていることを想定しています。

pythonを最新にする

pythonのバージョンを調べる

% brew search python

バージョンを指定せずにインストールすると、最新のフォーミュラ版がインストールされる

% brew install python

Homebrewでcsvkitをinstall

pipでインストールしようとしたらERROR:root:code for hash md5 was not found.と怒られたので困ってググったらHomebrewにcsvkitがいた!

% brew install csvkit

JsonファイルをCSVに変換

ベースのコマンドラインは以下。

% in2csv data.json > data.csv

option

よく使うであろうオプションは以下かなと思います。

-f - ファイルのフォーマットを指定する
-k - keyを指定する。ネストが深い場所のkeyを指定すると怒られるので、その場合はJSONファイルの整形が必要である。
--no-inference - 数値の0falseで出力されるのを防ぐ。

e.g)

in2csv data.json -k keyName -f json --no-inference > data.csv

参考サイト

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?