简体   繁体   中英

How to parse and convert a JSON file to a CSV file?

I have this JSON file:

{"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"}

I want to parse it and convert it to a CSV format, in which only the data are present (without the keys) and comma-separated.

Example:

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

How can I do it?

Use jq . It even has a CSV export option. I would not use awk or sed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM