Generate Json

I have an http extract that returns the following array.

"table": [ " <td width="7%">01/12/2023</td>
<td width="6%">0001726</td>
<td width="6%">VN</td>
<td width="20%">Janet C. Stout <br>
    <strong style="color:green"> * 1st Payment Method</strong>
</all>
<td width="6%">Company name</td>
<td width="10%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="7%" align="right">0.00</td>
<td width="7%" align="right">56.00</td>
<td width="7%">payment method</td>
<td width="7%">name of attendant</td>
<td width="7%" align="right">0.00</td>", " <td width="7%">01/12/2023</td>
<td width="6%">0001727</td>
<td width="6%">VN</td>
<td width="20%">Daisy J. Robinson <br>
    <strong style="color:green"> * 1st Payment Method</strong>
</all>
<td width="6%">Company name</td>
<td width="10%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="7%" align="right">0.00</td>
<td width="7%" align="right">26.00</td>
<td width="7%">payment method</td>
<td width="7%">name of attendant</td>
<td width="7%" align="right">0.00</td>", " <td width="7%">01/12/2023</td>
<td width="6%">0001728</td>
<td width="6%">VN</td>
<td width="20%">Phyllis A. Gibson <br>
    <strong style="color:green"> * 1st Payment Method</strong>
</all>
<td width="6%">Company name</td>
<td width="10%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="8%" align="right">0.00</td>
<td width="7%" align="right">0.00</td>
<td width="7%" align="right">89.00</td>
<td width="7%">payment method</td>
<td width="7%">name of attendant</td>
<td width="7%" align="right">0.00</td>" ] } ]

I would like to make the output be

data = {
      "client": {
          "0001726": {
              "id": 0001726,
              "date": "01/12/2023",
              "name": "Janet C. Stout",
              "Company": "Company name",
              "payment": "payment method",
              "price": "56.00"
          },
          "0001727": {
              "id": 0001727,
              "date": "01/12/2023",
              "name": "Daisy J. Robinson",
              "Company": "Company name",
              "payment": "payment method",
              "price": "56.00"
          },
          "0001728": {
              "id": 0001728,
              "date": "01/12/2023",
              "name": "Phyllis A. Gibson",
              "Company": "Company name",
              "payment": "payment method",
              "price": "89.00"
          }
      }
};

can anybody help me?

if anyone has the same doubt as me, follow the solution I found together with chatgpt.

var array = $node["Register"].json["html_data"];
var data = {
  "client": {}
};

for (var i = 0; i < array.length; i += 6) {
  let id =array[i+1];
  data.client[id] = {
    "id": id,
    "date": array[i],
    "name": array[i+2].replace(' * 1st Payment Method',''),
    "Company": array[i+3],
    "price": array[i+4],
    "payment": array[i+5]
  };
}

return data;
1 Like

Welcome to the community @LodSb! Glad to hear you figured it out, thanks so much for sharing your solution :slight_smile:

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