Handle Json file

Hello All,

I have the following Json file collected by logstash. The problem I'm facing is with Item ID as it add json nested object with for each item. The problem I can't build dashboards for these items with this structure.

I need your support to handle this data. maybe converting all items into array will help but I don't know how to do it.

        {
        	"TransactionUuid": "495b98ae-2764-4a45-a35c-6617c709cc94",
        	"TransactionId": "230422-115",
        	"CenterUuid": "02a46382-2226-496e-b7de-7de5757ddcf9",
        	"Type": "Sale",
        	"Status": "Paid",
        	"CanBeRefunded": true,
        	"Details": {
        		"PaidWithCash": 0.0,
        		"PaidWithCard": 29.0,
        		"PaidWithBalance": 0.0,
        		"CashReceived": 0.0,
        		"CardReceived": 29.0,
        		"Change": 0.0,
        		"DateTime": "2023-04-22T19:49:24.972Z",
        		"Employee": {
        			"Uuid": "3bd84952-ce56-4c86-8a81-928683880c1d",
        			"Name": "test"
        		},
        		"User": null,
        		"TotalQuantity": 2,
        		"TotalCoins": 0.0,
        		"TotalTaxes": 3.78,
        		"TotalGross": 29.0,
        		"TotalNet": 25.22,
        		"TotalDiscount": 0.0,
        		"CurrencyUuid": "8d40a467-d4dd-4e4d-b776-cab2e8128458"
        	},
        	"Items": {
        		"332795de-57cd-4e36-959a-c2ed488869a3": {
        			"Price": 20.0,
        			"TotalPrice": 20.0,
        			"ProductUuid": "332795de-57cd-4e36-959a-c2ed488869a3",
        			"Name": "test",
        			"Quantity": 1,
        			"CurrencyUuid": "8d40a467-d4dd-4e4d-b776-cab2e8128458",
        			"NetTotalValue": 17.39,
        			"GrossTotalValue": 20.0,
        			"Tax": {
        				"Id": "1",
        				"Name": "test",
        				"Percentage": 15.0,
        				"Square": null
        			},
        			"TaxTotalValue": 2.61,
        			"DiscountTotalValue": 0.0,
        			"CategoryUuid": "6074d4ba-daa6-4aea-9463-0ff9835c0046",
        			"IconUrl": "test",
        			"Description": null,
        			"IsCoupon": false
        		},
        		"239e55e9-c8ca-478e-81ce-1b9afc52e679": {
        			"Price": 9.0,
        			"TotalPrice": 9.0,
        			"ProductUuid": "239e55e9-c8ca-478e-81ce-1b9afc52e679",
        			"Name": "test",
        			"Quantity": 1,
        			"CurrencyUuid": "8d40a467-d4dd-4e4d-b776-cab2e8128458",
        			"NetTotalValue": 7.83,
        			"GrossTotalValue": 9.0,
        			"Tax": {
        				"Id": "1",
        				"Name": "test",
        				"Percentage": 15.0,
        				"Square": null
        			},
        			"TaxTotalValue": 1.17,
        			"DiscountTotalValue": 0.0,
        			"CategoryUuid": "ce1472db-b2e4-4483-b7d6-60edcc8a216c",
        			"IconUrl": "test",
        			"Description": null,
        			"IsCoupon": false
        		}
        	},
        	"Source": "Employee",
        	"RefundedAt": null,
        	"PackageDeals": [],
        	"StripePaymentIntentId": null,
        	"DeliveryDetails": null,
        	"Shipped": false,
        	"DeliveryDetailsFulfilled": true
        }

[Items] is a hash of hashes, where the key in the outer hash is the ProductUuid from the inner hash. You can convert that to an array using ruby, then use a split filter.

    ruby {
        code => '
            items = event.get("Items")
            if items
                a = []
                items.each { |k, v| a << v }
                event.set("Items", a)
            end
        '
    }
    split { field => "Items" }

Worked.

Thanks for your support.

I'm splitting the data based on transactionID already I can't use split again in order to maintain the relationship between the transaction and the items ordered .

I think i'm going to handle items filed as nested filed with ES mapping.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.