# Handle Json file

**URL:** <https://discuss.elastic.co/t/handle-json-file/330562>\
**Category:** Logstash\
**Created:** [April 22, 2023, 8:14pm UTC](https://discuss.elastic.co/t/handle-json-file/330562 "2023-04-22T20:14:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashraf123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashraf123/32/120097_2.png) [@Ashraf123](https://discuss.elastic.co/u/Ashraf123)\
**Post date:** [April 22, 2023, 8:14pm UTC](https://discuss.elastic.co/t/handle-json-file/330562/1 "2023-04-22T20:14:13Z")

</div>

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.

```auto
        {
        	"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
        }

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 22, 2023, 9:31pm UTC](https://discuss.elastic.co/t/handle-json-file/330562/2 "2023-04-22T21:31:42Z")

</div>

> [@Ashraf123](#):
>
> 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.

[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" }

```

---

<div class="post-metadata">

**Author:** ![Ashraf123](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashraf123/32/120097_2.png) [@Ashraf123](https://discuss.elastic.co/u/Ashraf123)\
**Post date:** [April 23, 2023, 3:35pm UTC](https://discuss.elastic.co/t/handle-json-file/330562/3 "2023-04-23T15:35:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 21, 2023, 3:36pm UTC](https://discuss.elastic.co/t/handle-json-file/330562/4 "2023-05-21T15:36:28Z")

</div>

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