Skip to main content

One post tagged with "jq"

View All Tags

Process JSON data using `jq`

· 2 min read
Daniel G
Developer

JSON is a widely used exchange format and we have many opportunities to process JSON data in daily work.

jq is a flexible and popular command-line JSON processor. It's very helpful to transform JSON data.

Here are my practical examples using jq to process JSON data.

The example JSON data (input.json) is like:

[
{
"id": "0c1160b4-42c9-4aee-8287-68b0cf03ebda",
"billingId": "54bdc967-0132-4cf2-9a9e-67d0230f7cce",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "DIRECT_DEBIT",
"createdAt": "2024-06-11T23:22:54.777Z",
"refundAmount": 29.9,
"refundDate": "2024-05-30",
"updatedAt": "2024-06-11T23:22:54.777Z"
},
{
"id": "4fa36c92-a1c1-44be-bd5e-f0697fd91420",
"billingId": "4f13d5f9-d0d9-470f-8e98-d5c6a37ac428",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "CREDIT_CARD",
"createdAt": "2024-06-11T23:22:54.777Z",
"memberId": "52dd5dfc-82d2-526f-b3ef-f0df008eb37a",
"refundAmount": 13.0,
"refundDate": "2024-05-30",
"updatedAt": "2024-06-11T23:22:54.777Z"
},
{
"id": "3ff9266a-18f6-4473-ac9c-ac99d28c608e",
"billingId": "4823b60d-79ca-411b-a993-9d9b3d4f2350",
"requestBy": "6b303448-4010-4ab8-a3dc-30bbd4145475",
"paymentType": "CREDIT_CARD",
"createdAt": "2024-05-11T23:22:54.777Z",
"memberId": "9f993c23-e3ab-4a65-93ed-5fe4c343843c",
"refundAmount": 38.0,
"refundDate": "2024-06-30",
"updatedAt": "2024-06-28T23:22:54.777Z"
}
]