# How to separate objects inside an array of objects?

**URL:** <https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274>\
**Category:** Logstash\
**Created:** [July 21, 2022, 11:08am UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274 "2022-07-21T11:08:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mary2022](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Mary2022](https://discuss.elastic.co/u/Mary2022)\
**Post date:** [July 21, 2022, 11:08am UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274/1 "2022-07-21T11:08:08Z")

</div>

Hi,

I still new to ELK and I have been trying to process data that come to me as json file. The json file looks lie this.

```auto
[
	{
		"user": "Beta",
		"percent": 28,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987793,
		"Location": "locationB",
		"desk": "MAC"
	},
	{
		"user": "Alpha",
		"percent": 86,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987733,
		"Location": "locationA",
		"desk": "LIN"
	},
	{
		"user": "Charlie",
		"percent": 03,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987724,
		"Location": "locationA",
		"desk": "LIN"
	},

	{
		"user": "test",
		"percent": 15,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987778,
		"Location": "locationB",
		"desk": "MAC"
	},

	{
		"user": "Delta",
		"percent": 28,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987793,
		"Location": "location1",
		"desk": "MAC"
	},

	{
		"user": "Juliana",
		"percent": 28,
		"startTime": "2022-07-07T11:31:45",
		"type": "CPU",
		"total": 1072987793,
		"Location": "location1",
		"desk": "MAC"
	}
]

```

Each object inside of that array has to be index. Is there a way to do that? How can I separate or process each object separate?

---

<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:** [July 21, 2022, 12:46pm UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274/2 "2022-07-21T12:46:45Z")

</div>

If you want each entry in the array to be a separate event then use a [split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-split.html) filter.

---

<div class="post-metadata">

**Author:** ![Mary2022](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Mary2022](https://discuss.elastic.co/u/Mary2022)\
**Post date:** [July 22, 2022, 10:39am UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274/3 "2022-07-22T10:39:00Z")

</div>

I added the split filter but I am not sure if I am using it right since my array doesn't have a field name/id before the array of objects starts. Below is what I am planning to try today and I added some comments with what I am trying to get but I feel like maybe I need a loop or so.

```auto

#This is my input:

input {
	http {
		port => 8287
		ssl => true
		ssl_certificate_authorities => ["xxxxxxxxxxxxxxxx.crt"]
		ssl_certificate => "path.crt"
		ssl_key => "xxxxxxxxxxxxxxxxxx"
		ssl_verify_mode => peer
	}
}

filter {

	split {
		field => "/n"
	}
#After split I want each object to be parse shoudl I use json filter?
	json {source => "message"}

#Then I want to use this grock for the parse of each object/event
	grok {
	match => { "desktop" => "(?<site>^.{2}%{DATA}-%{DATA}%{INT:pod}%{GREEDYDATA}" }
	}

#I want to add and remove fields in each object/event	
	mutate {
	add_field => { 'processed_at' => "%{@timestamp}" }
	remove_field => ["headers"]
	}

	date {
		match => ['startTime', "yyyy-MM-dd'T'HH:mm:ss", "ISO8601"]
		remove_field => ['startTime']
	}
}

#Then I want to send/index each event that was parse.
output {

elasticsearch {
	hosts=>["https:xxxxxx:9200, "https:xxxxxx:9200]
	index => "testCM"
	user => XXXX
	password => "xxxxxxxxx"
	keystore => "xxxx.jks"
	keystore_password => "xxxxxx"
	cacert => "xxxxxxxxxxxxx.crt"
	}
}

```

---

<div class="post-metadata">

**Author:** ![Mary2022](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Mary2022](https://discuss.elastic.co/u/Mary2022)\
**Post date:** [July 26, 2022, 6:56pm UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274/4 "2022-07-26T18:56:51Z")

</div>

Does the below sounds right?

---

<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:** [August 23, 2022, 6:57pm UTC](https://discuss.elastic.co/t/how-to-separate-objects-inside-an-array-of-objects/310274/5 "2022-08-23T18:57:48Z")

</div>

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