0

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:

06001,Pippo,,,, 06002,Pluto,123456789,0.01,ferrari 

Thanks all.

7
  • ...and what specific problem did you encounter while doing this yourself? Commented Mar 25, 2022 at 15:12
  • (if the problem is combining the values from upper layers, as $varname to store data from upper layers to use in lower ones is your friend; we have existing Q&A that already describes how to do this) Commented Mar 25, 2022 at 15:13
  • Note that the two linked duplicates should be used in combination. The former one talks about how to get values from outer layers into the inner ones; the latter talks about how to get your data into CSV form. Commented Mar 25, 2022 at 15:15
  • I have not found a same question to be duplicated. But my problem is adapt the script in the link I found to my case. Commented Mar 25, 2022 at 15:21
  • See replit.com/@CharlesDuffy2/MetallicGrowingDecompilers#main.sh as an example showing how to apply the linked duplicates to your exact input, to receive your exact output. Commented Mar 25, 2022 at 17:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.