Skip to main content
added 17 characters in body
Source Link
Charles Duffy
  • 299.3k
  • 43
  • 441
  • 497
{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 
{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] } } } 
transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 
06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 
{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 
transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 
{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] } } } 
06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 
added 199 characters in body
Source Link
Bombo
  • 147
  • 1
  • 1
  • 10

Hy guys, Given an array of JSON objects, I'd like to output a CSV, but in this case i have a different keys and i need to take some values through JSONs' multiple layers.

i'm not skill with a bash script. i have found that link Convert json to csv using jq with different key but I don't know how to adapt it to my case

My Json file:

{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 

the correct output:

transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 

Thanks all.

Hy guys, Given an array of JSON objects, I'd like to output a CSV, but in this case i have a different keys and i need to take some values through JSONs' multiple layers.

My Json file:

{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 

the correct output:

transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 

Thanks all.

Hy guys, Given an array of JSON objects, I'd like to output a CSV, but in this case i have a different keys and i need to take some values through JSONs' multiple layers.

i'm not skill with a bash script. i have found that link Convert json to csv using jq with different key but I don't know how to adapt it to my case

My Json file:

{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 

the correct output:

transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 

Thanks all.

Post Closed as "Duplicate" by Charles Duffy bash
Source Link
Bombo
  • 147
  • 1
  • 1
  • 10

Bash Convert json to csv using jq with different key multilayer

Hy guys, Given an array of JSON objects, I'd like to output a CSV, but in this case i have a different keys and i need to take some values through JSONs' multiple layers.

My Json file:

{ "status": "success", "data": { "n_per_page": 10, "transactions_by_dealer_code": { "06001": [ { "dealer_name": "Pippo", "dealer_total_transaction_count": 0, "dealer_cancellation_count": 0, "dealer_reservation_count": 0, "transactons_detail": [] } ], "06003": [ { "dealer_name": "Pluto", "dealer_total_transaction_count": 1, "dealer_cancellation_count": 0, "dealer_reservation_count": 1, "transactons_detail": [ { "transaction_id": "123456789", "deposite_amount": 0.01, "vehicle_make": "ferrari" } ] } ] 

the correct output:

transactions_by_dealer_code,dealer_name,transaction_id,deposite_amount,vehicle_make 06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 

Thanks all.