# How to Parse the XML logs in Logstash and Convert into Json

**URL:** <https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035>\
**Category:** Logstash\
**Created:** [April 9, 2022, 5:41pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035 "2022-04-09T17:41:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lolo\_prime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lolo_prime/32/104204_2.png) [@lolo\_prime](https://discuss.elastic.co/u/lolo_prime)\
**Post date:** [April 9, 2022, 5:41pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035/1 "2022-04-09T17:41:31Z")

</div>

i want to convert xml input to json data. The xml format is shown below

---

<div class="post-metadata">

**Author:** ![lolo\_prime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lolo_prime/32/104204_2.png) [@lolo\_prime](https://discuss.elastic.co/u/lolo_prime)\
**Post date:** [April 9, 2022, 5:45pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035/3 "2022-04-09T17:45:43Z")

</div>

```auto
<PurchaseOrders>
	<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
		<Address Type="Shipping">
			<Name>Ellen Adams</Name>
			<Street>123 Maple Street</Street>
			<City>Mill Valley</City>
			<State>CA</State>
			<Zip>10999</Zip>
			<Country>USA</Country>
		</Address>
		<DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
		<Items>
			<Item PartNumber="872-AA">
				<ProductName>Lawnmower</ProductName>
				<Quantity>1</Quantity>
				<USPrice>148.95</USPrice>
				<Comment>Confirm this is electric</Comment>
			</Item>
			<Item PartNumber="926-AA">
				<ProductName>Baby Monitor</ProductName>
				<Quantity>2</Quantity>
				<USPrice>39.98</USPrice>
				<ShipDate>1999-05-21</ShipDate>
			</Item>
		</Items>
	</PurchaseOrder>
	<PurchaseOrder PurchaseOrderNumber="99505" OrderDate="1999-10-22">
		<Address Type="Shipping">
			<Name>Cristian Osorio</Name>
			<Street>456 Main Street</Street>
			<City>Buffalo</City>
			<State>NY</State>
			<Zip>98112</Zip>
			<Country>USA</Country>
		</Address>
		<Address Type="Billing">
			<Name>Cristian Osorio</Name>
			<Street>456 Main Street</Street>
			<City>Buffalo</City>
			<State>NY</State>
			<Zip>98112</Zip>
			<Country>USA</Country>
		</Address>
		<DeliveryNotes>Please notify me before shipping.</DeliveryNotes>
		<Items>
			<Item PartNumber="456-NM">
				<ProductName>Power Supply</ProductName>
				<Quantity>1</Quantity>
				<USPrice>45.99</USPrice>
			</Item>
		</Items>
	</PurchaseOrder>
	<PurchaseOrder PurchaseOrderNumber="99504" OrderDate="1999-10-22">
		<Address Type="Shipping">
			<Name>Jessica Arnold</Name>
			<Street>4055 Madison Ave</Street>
			<City>Seattle</City>
			<State>WA</State>
			<Zip>98112</Zip>
			<Country>USA</Country>
		</Address>
		<Address Type="Billing">
			<Name>Jessica Arnold</Name>
			<Street>4055 Madison Ave</Street>
			<City>Buffalo</City>
			<State>NY</State>
			<Zip>98112</Zip>
			<Country>USA</Country>
		</Address>
		<Items>
			<Item PartNumber="898-AZ">
				<ProductName>Computer Keyboard</ProductName>
				<Quantity>1</Quantity>
				<USPrice>29.99</USPrice>
			</Item>
			<Item PartNumber="898-AM">
				<ProductName>Wireless Mouse</ProductName>
				<Quantity>1</Quantity>
				<USPrice>14.99</USPrice>
			</Item>
		</Items>
	</PurchaseOrder>
</PurchaseOrders>

```

---

<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 9, 2022, 6:27pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035/4 "2022-04-09T18:27:26Z")

</div>

You may need to use a [multiline codec](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-multiline.html) to combine lines so that the entire XML object is in a single event, then use an [xml filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-xml.html) to parse it.

There are many threads that discuss this. [Here](https://discuss.elastic.co/t/console-xml-works-but-not-file-xml/206645) is one.

---

<div class="post-metadata">

**Author:** ![lolo\_prime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lolo_prime/32/104204_2.png) [@lolo\_prime](https://discuss.elastic.co/u/lolo_prime)\
**Post date:** [April 11, 2022, 5:02pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035/5 "2022-04-11T17:02:44Z")

</div>

Thank You

---

<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 9, 2022, 5:03pm UTC](https://discuss.elastic.co/t/how-to-parse-the-xml-logs-in-logstash-and-convert-into-json/302035/6 "2022-05-09T17:03:40Z")

</div>

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