JQ - json
by WiglWagl from LinuxQuestions.org on (#6EP63)
Hello,
i need help to convert a json to csv with JQ
Code:{
"id": 2050,
"parent_id": 0,
"status": "completed",
"currency": "EUR",
"version": "7.7.1",
"prices_include_tax": false,
"date_created": "2023-08-24T08:26:34",
"date_modified": "2023-08-24T10:11:26",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "7.90",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "48.60",
"total_tax": "0.00",
"customer_id": 0,
"order_key": "wc_order_VLwtLM4lUS2iV",
"billing": {
"first_name": "Julia",
"last_name": "Mith\u00f6fer",
"company": "",
"address_1": "Muster Str.",
"address_2": "7",
"city": "Musterstrasse",
"state": "",
"postcode": "49134",
"country": "DE",
"email": "Muster@gmx.net",
"phone": "01607532299"
},
"shipping": {
"first_name": "Test",
"last_name": "Mith\u00f6fer",
"company": "",
"address_1": "Muster Str.",
"address_2": "7",
"city": "Wallenhorst",
"state": "",
"postcode": "49134",
"country": "DE",
"phone": ""
},
"payment_method": "ppcp-gateway",
"created_via": "checkout",
"customer_note": "",
"date_completed": "2023-08-24T10:11:26",
"date_paid": "2023-08-24T08:26:38",
"cart_hash": "0d05161b04c8b1fc417d0cbbc011c042",
"number": "2050",
"meta_data": [{
"id": 22153,
"key": "is_vat_exempt",
"value": "no"
}, {
"id": 22154,
"key": "_ppcp_paypal_order_id",
"value": "078843904C039722A"
}, {
"id": 22155,
"key": "_ppcp_paypal_intent",
"value": "CAPTURE"
}, {
"id": 22156,
"key": "_ppcp_paypal_payment_mode",
"value": "live"
}, {
"id": 22160,
"key": "_ppcp_paypal_fees",
"value": {
"gross_amount": {
"currency_code": "EUR",
"value": "48.60"
},
"paypal_fee": {
"currency_code": "EUR",
"value": "2.00"
},
"net_amount": {
"currency_code": "EUR",
"value": "46.60"
}
}
}, {
"id": 22161,
"key": "PayPal Transaction Fee",
"value": "2"
}],
"line_items": [{
"id": 320,
"name": "Bilderbuch \u00abBetty brennt durch\u00bb",
"product_id": 437,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "18.90",
"subtotal_tax": "0.00",
"total": "18.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235273",
"price": 18.899999999999999,
"image": {
"id": "101",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/betty-brennt-durch-web.jpg"
},
"parent_name": null
}, {
"id": 321,
"name": "Poster \u00abHundesprache\u00bb",
"product_id": 536,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "5.90",
"subtotal_tax": "0.00",
"total": "5.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235274",
"price": 5.9000000000000004,
"image": {
"id": "107",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/poster-web.jpg"
},
"parent_name": null
}, {
"id": 322,
"name": "Memospiel \u00abHundesprache\u00bb",
"product_id": 1725,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "15.90",
"subtotal_tax": "0.00",
"total": "15.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235276",
"price": 15.9,
"image": {
"id": "1818",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/wau-statt-au-memory-05.jpg"
},
"parent_name": null
}],
"tax_lines": [],
"shipping_lines": [{
"id": 323,
"method_title": "\u00d6sterreichische Post",
"method_id": "flat_rate",
"instance_id": "2",
"total": "7.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [{
"id": 2513,
"key": "Positionen",
"value": "Bilderbuch \u00abBetty brennt durch\u00bb × 1, Poster \u00abHundesprache\u00bb × 1, Memospiel \u00abHundesprache\u00bb × 1",
"display_key": "Positionen",
"display_value": "Bilderbuch \u00abBetty brennt durch\u00bb × 1, Poster \u00abHundesprache\u00bb × 1, Memospiel \u00abHundesprache\u00bb × 1"
}]
}],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"payment_url": "https:\/\/www.wau-statt-au.at\/kasse\/order-pay\/2050\/?pay_for_order=true&key=wc_order_VLwtLM4lUS2iV",
"is_editable": false,
"needs_payment": false,
"needs_processing": true,
"date_created_gmt": "2023-08-24T06:26:34",
"date_modified_gmt": "2023-08-24T08:11:26",
"date_completed_gmt": "2023-08-24T08:11:26",
"date_paid_gmt": "2023-08-24T06:26:38",
"currency_symbol": "\u20ac",
"_links": {
"self": [{
"href": "https:\/\/www.wau-statt-au.at\/wp-json\/wc\/v3\/orders\/2050"
}],
"collection": [{
"href": "https:\/\/www.wau-statt-au.at\/wp-json\/wc\/v3\/orders"
}]
}
}I need the "line_items" in a row. Can someone tell me how the JQ should look like?
I tried this:
Code:jq '.billing.email,.id,.order_key,.date_created,.status,.billing.first_name,.billing.last_name,.billing.company,.billing.address_1,.billing.adress_2,.billing.city,.billing.state,.billing.postcode,.billing.country,.billing.phone,.shipping.first_name,.shipping.last_name,.shipping.company,.shipping.adress_1,.shipping.adress_2,.shipping.city,.shipping.state,.shipping.postcode,.shipping.country,.shipping_lines[].method_title,.shipping_lines[].total,.coupon_lines[].code,.coupon_lines[].discount,.line_items[].quantity,.line_items[].sku,.line_items[].subtotal,.line_items[].subtotal_tax,.line_items[].total,.line_items[].total_tax' rmtmp/X.GETORDER.20230912094815.TMPBut with that i get each value in ein new line. And the "line_items" are mixes, first three times quantity thant 3 times product sku,...
thanks
WW
i need help to convert a json to csv with JQ
Code:{
"id": 2050,
"parent_id": 0,
"status": "completed",
"currency": "EUR",
"version": "7.7.1",
"prices_include_tax": false,
"date_created": "2023-08-24T08:26:34",
"date_modified": "2023-08-24T10:11:26",
"discount_total": "0.00",
"discount_tax": "0.00",
"shipping_total": "7.90",
"shipping_tax": "0.00",
"cart_tax": "0.00",
"total": "48.60",
"total_tax": "0.00",
"customer_id": 0,
"order_key": "wc_order_VLwtLM4lUS2iV",
"billing": {
"first_name": "Julia",
"last_name": "Mith\u00f6fer",
"company": "",
"address_1": "Muster Str.",
"address_2": "7",
"city": "Musterstrasse",
"state": "",
"postcode": "49134",
"country": "DE",
"email": "Muster@gmx.net",
"phone": "01607532299"
},
"shipping": {
"first_name": "Test",
"last_name": "Mith\u00f6fer",
"company": "",
"address_1": "Muster Str.",
"address_2": "7",
"city": "Wallenhorst",
"state": "",
"postcode": "49134",
"country": "DE",
"phone": ""
},
"payment_method": "ppcp-gateway",
"created_via": "checkout",
"customer_note": "",
"date_completed": "2023-08-24T10:11:26",
"date_paid": "2023-08-24T08:26:38",
"cart_hash": "0d05161b04c8b1fc417d0cbbc011c042",
"number": "2050",
"meta_data": [{
"id": 22153,
"key": "is_vat_exempt",
"value": "no"
}, {
"id": 22154,
"key": "_ppcp_paypal_order_id",
"value": "078843904C039722A"
}, {
"id": 22155,
"key": "_ppcp_paypal_intent",
"value": "CAPTURE"
}, {
"id": 22156,
"key": "_ppcp_paypal_payment_mode",
"value": "live"
}, {
"id": 22160,
"key": "_ppcp_paypal_fees",
"value": {
"gross_amount": {
"currency_code": "EUR",
"value": "48.60"
},
"paypal_fee": {
"currency_code": "EUR",
"value": "2.00"
},
"net_amount": {
"currency_code": "EUR",
"value": "46.60"
}
}
}, {
"id": 22161,
"key": "PayPal Transaction Fee",
"value": "2"
}],
"line_items": [{
"id": 320,
"name": "Bilderbuch \u00abBetty brennt durch\u00bb",
"product_id": 437,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "18.90",
"subtotal_tax": "0.00",
"total": "18.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235273",
"price": 18.899999999999999,
"image": {
"id": "101",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/betty-brennt-durch-web.jpg"
},
"parent_name": null
}, {
"id": 321,
"name": "Poster \u00abHundesprache\u00bb",
"product_id": 536,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "5.90",
"subtotal_tax": "0.00",
"total": "5.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235274",
"price": 5.9000000000000004,
"image": {
"id": "107",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/poster-web.jpg"
},
"parent_name": null
}, {
"id": 322,
"name": "Memospiel \u00abHundesprache\u00bb",
"product_id": 1725,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "15.90",
"subtotal_tax": "0.00",
"total": "15.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [],
"sku": "235276",
"price": 15.9,
"image": {
"id": "1818",
"src": "https:\/\/www.wau-statt-au.at\/wp-content\/uploads\/wau-statt-au-memory-05.jpg"
},
"parent_name": null
}],
"tax_lines": [],
"shipping_lines": [{
"id": 323,
"method_title": "\u00d6sterreichische Post",
"method_id": "flat_rate",
"instance_id": "2",
"total": "7.90",
"total_tax": "0.00",
"taxes": [],
"meta_data": [{
"id": 2513,
"key": "Positionen",
"value": "Bilderbuch \u00abBetty brennt durch\u00bb × 1, Poster \u00abHundesprache\u00bb × 1, Memospiel \u00abHundesprache\u00bb × 1",
"display_key": "Positionen",
"display_value": "Bilderbuch \u00abBetty brennt durch\u00bb × 1, Poster \u00abHundesprache\u00bb × 1, Memospiel \u00abHundesprache\u00bb × 1"
}]
}],
"fee_lines": [],
"coupon_lines": [],
"refunds": [],
"payment_url": "https:\/\/www.wau-statt-au.at\/kasse\/order-pay\/2050\/?pay_for_order=true&key=wc_order_VLwtLM4lUS2iV",
"is_editable": false,
"needs_payment": false,
"needs_processing": true,
"date_created_gmt": "2023-08-24T06:26:34",
"date_modified_gmt": "2023-08-24T08:11:26",
"date_completed_gmt": "2023-08-24T08:11:26",
"date_paid_gmt": "2023-08-24T06:26:38",
"currency_symbol": "\u20ac",
"_links": {
"self": [{
"href": "https:\/\/www.wau-statt-au.at\/wp-json\/wc\/v3\/orders\/2050"
}],
"collection": [{
"href": "https:\/\/www.wau-statt-au.at\/wp-json\/wc\/v3\/orders"
}]
}
}I need the "line_items" in a row. Can someone tell me how the JQ should look like?
I tried this:
Code:jq '.billing.email,.id,.order_key,.date_created,.status,.billing.first_name,.billing.last_name,.billing.company,.billing.address_1,.billing.adress_2,.billing.city,.billing.state,.billing.postcode,.billing.country,.billing.phone,.shipping.first_name,.shipping.last_name,.shipping.company,.shipping.adress_1,.shipping.adress_2,.shipping.city,.shipping.state,.shipping.postcode,.shipping.country,.shipping_lines[].method_title,.shipping_lines[].total,.coupon_lines[].code,.coupon_lines[].discount,.line_items[].quantity,.line_items[].sku,.line_items[].subtotal,.line_items[].subtotal_tax,.line_items[].total,.line_items[].total_tax' rmtmp/X.GETORDER.20230912094815.TMPBut with that i get each value in ein new line. And the "line_items" are mixes, first three times quantity thant 3 times product sku,...
thanks
WW