# RESOLVED: Convert HTML to Array of Objects

**URL:** <https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470>\
**Category:** General\
**Created:** [28 March 2022 20:18 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470 "2022-03-28T20:18:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![plfinch](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@plfinch](https://discourse.nodered.org/u/plfinch)\
**Post date:** [28 March 2022 20:18 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470/1 "2022-03-28T20:18:47Z")

</div>

I have an html response containing item element tags and subelement tags within. I want to convert this to an array of item objects containing the item elements. Here is a very simplified version of the HTML:

```auto
<rss>
  <item>
    <title>Alert Number 1</title>
    <description>Description Number 1</description>
  </item>
  <item>
    <title>Alert Number 1</title>
    <description>Description Number 1</description>
  </item>
</rss>

```

Here is the desired JSON output:

```auto
[
    {
        "title": "Alert Number 1",
        "description": "Description Number 1"
    },
    {
        "title": "Alert Number 2",
        "description": "Description Number 2"
    }
]

```

I thought I'd be able to do this easily with the Edit html node but that gets me item objects with the elements combined in a string or html, rather than object elements. The simple flow below shows what I want and what I get with the html option in the Edit html node.

```auto
[{"id":"bdbbd45b058fddfe","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"69d37d2a1234967a","type":"debug","z":"bdbbd45b058fddfe","name":"Output JSON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"output","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":200,"wires":[]},{"id":"99da6278232eb673","type":"html","z":"bdbbd45b058fddfe","name":"Get Items - HTML","property":"payload","outproperty":"output","tag":"item","ret":"html","as":"single","x":330,"y":200,"wires":[["54533185b06f155b","69d37d2a1234967a","ecf7b8348d823484"]]},{"id":"ecf7b8348d823484","type":"debug","z":"bdbbd45b058fddfe","name":"Desired JSON","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"desired","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":240,"wires":[]},{"id":"eee8c7a43f66f6b1","type":"inject","z":"bdbbd45b058fddfe","name":"Setup","props":[{"p":"payload"},{"p":"desired","v":"[{\"title\":\"Alert Number 1\",\"description\":\"Description Number 1\"},{\"title\":\"Alert Number 2\",\"description\":\"Description Number 2\"}]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<rss> <item> <title>Alert Number 1</title> <description>Description Number 1</description> </item> <item> <title>Alert Number 1</title> <description>Description Number 1</description> </item> </rss>","payloadType":"str","x":150,"y":200,"wires":[["99da6278232eb673"]]},{"id":"54533185b06f155b","type":"debug","z":"bdbbd45b058fddfe","name":"HTML Source","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":160,"wires":[]}]

```

So what is the best/easiest/proper method to achieve this?

[For those who notice this is actually an RSS parser, the feedparser node does not contain the initialization and timing control that I need. The user contrib versions with input could work but are overkill for what I am doing.]

Peter

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 20:36 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470/2 "2022-03-28T20:36:03Z")

</div>

Try feeding it through an xml node.

---

<div class="post-metadata">

**Author:** ![plfinch](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@plfinch](https://discourse.nodered.org/u/plfinch)\
**Post date:** [28 March 2022 20:40 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470/3 "2022-03-28T20:40:45Z")

</div>

DOH! Yeah, that works fine. Thanks!

Peter

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 March 2022 20:46 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470/4 "2022-03-28T20:46:56Z")

</div>

Excellent. Glad to be of help.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 April 2022 20:47 UTC](https://discourse.nodered.org/t/resolved-convert-html-to-array-of-objects/60470/5 "2022-04-11T20:47:52Z")

</div>

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