我从json开始,看起来是这样的:
{ "object": "list", "data": [ "id": "in_1HW85aFGUwFHXzvl8wJbW7V7", "object": "invoice", "account_country": "US", "customer_name": "clientOne", "date": 1601244686, "livemode": true, "metadata": {}, "paid": true, "status": "paid", "total": 49500 "id": "in_1HJlIZFGUwFHXzvlWqhegRkf", "object": "invoice", "account_country": "US", "customer_name": "clientTwo", "date": 1598297143, "livemode": true, "metadata": {}, "paid": true, "status": "paid", "total": 51000 "id": "in_1HJkg5FGUwFHXzvlYp2uC63C", "object": "invoice", "account_country": "US", "customer_name": "clientThree", "date": 1598294757, "livemode": true, "metadata": {}, "paid": true, "status": "paid", "total": 57000 "id": "in_1H8B0pFGUwFHXzvlU6nrOm6I", "object": "invoice", "account_country": "US", "customer_name": "clientThree", "date": 1595536051, "livemode": true, "metadata": {}, "paid": true, "status": "paid", "total": 20000 "has_more": true, "url": "/v1/invoices" }
如果我做了
cat sample.json | jq -C '.data[] | {invoice_id: .id, date: .date | strftime("%Y-%m-%d"), amount: .total} | .amount = "$" + (.amount/100|tostring)'
我可以成功地整理这个数据(实际的数据要详细得多,数百行要删除),这给了我:
{ "invoice_id": "in_1HW85aFGUwFHXzvl8wJbW7V7", "date": "2020-09-27", "amount": "$495" "invoice_id": "in_1HJlIZFGUwFHXzvlWqhegRkf", "date": "2020-08-24", "amount": "$510" "invoice_id": "in_1HJkg5FGUwFHXzvlYp2uC63C", "date": "2020-08-24", "amount": "$570" "invoice_id": "in_1H8B0pFGUwFHXzvlU6nrOm6I", "date": "2020-07-23",