如何解析JSON文件并将其转换为CSV文件?

时间:2015-07-28 11:57:47

标签: json linux parsing awk sed

我有这个JSON文件:

{"id":"797b80c2-b0f4-435a-96a1-8e88cd4af438","user":4006,"bet_id":3165922,"a_b_test_group":"Test1","a_b_test_name":"VariantB","amount":7757252.0764807705,"application":"My App","bet_type":"G","bonus_balance":4190408.7684564292,"bonus_game_id":7326847,"eor_xp":5950699.737405404,"fact":"Bet","first_session_indicator":0,"isfirstsession":"NO","machine_name":"Dragons","machine_position":5,"machine_status":"Status1","money_type":"USD","multiplier":199,"platform":"Web","play_mode":"B","player_level":117,"position":113,"real_balance":2313648.2257242315,"real_bet_amount":8598060,"referral":"CMP675","round_speed":"Hyperspeed","round_type":"Type1","sessionid":"83287993-e191-4773-a37c-a524a5ecd6c5","session_id":"b3254d5a-e9ab-46c9-95a7-c33c56070653","time":"2015-07-05T05:24:13.792Z","window":"[[\"C\",\"G\",\"H\",\"B\",\"A\"],[\"G\",\"I\",\"E\",\"B\",\"J\"],[\"D\",\"F\",\"G\",\"I\",\"G\"],[\"H\",\"G\",\"H\",\"B\",\"E\"],[\"D\",\"I\",\"H\",\"K\",\"K\"]]","winning_amount":4959979.609602829,"winning_position":74,"__updatetime":"2015-07-24T11:57:13.793Z","__messageid":"1b9af0c9-fbea-4847-a1e7-66d0d62f7854","__entryidx":"B715","__queue":"My Queue","__sqs_sent_time":"2015-07-24T11:57:13.793Z"}

我想解析它并将其转换为CSV格式,其中只存在数据(没有键)和逗号分隔。

示例:

"797b80c2-b0f4-435a 96a1-8e88cd4af438",4006,3165922,"Test1","VariantB",7757252.0764807705,"My App"

我该怎么做?

1 个答案:

答案 0 :(得分:3)

使用jq。它甚至还有一个CSV导出选项。我不会使用awk或sed。