2017-02-19 19 views
0

下記の "test.json"というjsonファイルがあり、これをCSVファイルに変換したいと考えています。私はPythonのパンダで試しましたが、残念ながら成功しませんでした。 誰かからの援助は本当に感謝しています。ここでjsonファイルをCSVに変換するための支援が必要

{ 
 
\t "epoch": 1487237243.000440, 
 
\t "comment": null, 
 
\t "header": "mac[#mode|_rate]  : latitude  longitude range  max  age sig_A noise_A sig_B noise_B num loss  kBps", 
 
\t "data": { 
 
\t \t "04:e5:48:01:73:29#0000": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -96.00, -98.00, 2, 0, 0.138], 
 
\t \t "04:e5:48:01:73:29#0001": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.50, -101.00, -96.50, -102.50, 2, 0, 0.438], 
 
\t \t "04:e5:48:01:73:29#0002": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.50, -99.50, -96.00, -101.00, 2, 0, 1.538], 
 
\t \t "04:e5:48:01:73:29#0003": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -97.00, -101.00, 1, 0, 0.138], 
 
\t \t "04:e5:48:01:73:29#0004": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -96.00, -101.00, 1, 0, 0.438], 
 
\t \t "04:e5:48:01:73:29#0005": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -95.00, -98.00, 1, 0, 1.538], 
 
\t \t "04:e5:48:01:73:29#0006": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -95.00, -98.00, 1, 0, 0.138], 
 
\t \t "04:e5:48:01:73:29#0007": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -96.50, -101.00, 2, 0, 0.438], 
 
\t \t "04:e5:48:01:73:29#0008": [48.1499800, 11.5833270, -1.00, 0.00, 0.00, -80.00, -101.00, -96.50, -99.50, 2, 0, 1.538] 
 
\t } 
 
}

答えて

1

jqを使用したソリューションです。

filter.jq

[ .header | match("[^: ]+";"g") | .string ] 
, (.data | keys[] as $k | [$k] + .[$k]) 
| @csv 

data.json次いで

$ jq -M -r -f filter.jq data.json 

jsonlitedplyrを用い

"mac[#mode|_rate]","latitude","longitude","range","max","age","sig_A","noise_A","sig_B","noise_B","num","loss","kBps" 
"04:e5:48:01:73:29#0000",48.14998,11.583327,-1,0,0,-80,-101,-96,-98,2,0,0.138 
"04:e5:48:01:73:29#0001",48.14998,11.583327,-1,0,0,-80.5,-101,-96.5,-102.5,2,0,0.438 
"04:e5:48:01:73:29#0002",48.14998,11.583327,-1,0,0,-80.5,-99.5,-96,-101,2,0,1.538 
"04:e5:48:01:73:29#0003",48.14998,11.583327,-1,0,0,-80,-101,-97,-101,1,0,0.138 
"04:e5:48:01:73:29#0004",48.14998,11.583327,-1,0,0,-80,-101,-96,-101,1,0,0.438 
"04:e5:48:01:73:29#0005",48.14998,11.583327,-1,0,0,-80,-101,-95,-98,1,0,1.538 
"04:e5:48:01:73:29#0006",48.14998,11.583327,-1,0,0,-80,-101,-95,-98,1,0,0.138 
"04:e5:48:01:73:29#0007",48.14998,11.583327,-1,0,0,-80,-101,-96.5,-101,2,0,0.438 
"04:e5:48:01:73:29#0008",48.14998,11.583327,-1,0,0,-80,-101,-96.5,-99.5,2,0,1.538 
0

別の溶液を生成するサンプルデータを含む次のフィルタが含まれている場合:

install.packages(c("jsonlite","dplyr")) 
library(jsonlite) 
library(dplyr) 

# asumme your file is "my_file.json" 
my_data <- as_tibble(fromJSON("my_file.json")) 
関連する問題