Joining fields by key

Hi,

Please can someone help me with this, I have some json and inside the json is an identifier that I want to use as a key so I can combine all the names of landlords and tenants into landlord or tenant groups.

For example I might have Mr Landlord 1 and in another part of the array Mr Landlord 2 and I want to be able create a new name text field that reads Mr Landlord 1 & Mr Landlord 2.

I guess I need a function to split out the json by the identifier which is nested under field_30_raw, but I do not know how to do that in this case. Here is some original json I am working from:

[
  {
    "id": "646351cbf3c4080028bad42a",
    "field_30": "<span class=\"64478ada2cdb530028dc2a18\">Landlord</span>",
    "field_30_raw": [
      {
        "id": "64478ada2cdb530028dc2a18",
        "identifier": "Landlord"
      }
    ],
    "field_52": "<span class=\"6461e83c5d017100282971da\">Mr Landlord</span>",
    "field_52_raw": [
      {
        "id": "6461e83c5d017100282971da",
        "identifier": "Mr Landlord"
      }
    ],
    "field_3": "Mr Paul Test",
    "field_3_raw": "Mr Paul Test",
    "field_23": "112 High Street<br />Mascot, NSW 2020<br />Australia",
    "field_23_raw": {
      "street": "112 High Street",
      "street2": null,
      "city": "Mascot",
      "state": "NSW",
      "zip": "2020",
      "country": "Australia",
      "longitude": 151.18767,
      "latitude": -33.93015,
      "full": "112 High Street Mascot, NSW 2020 Australia"
    },
    "field_24": "<a href=\"mailto:[email protected]\">[email protected]</a>",
    "field_24_raw": {
      "email": "[email protected]",
      "label": null
    },
    "field_25": "",
    "field_25_raw": "",
    "field_61": "Mr Paul Clarke Landlord",
    "field_61_raw": "Mr Paul Clarke Landlord",
    "field_86": "No",
    "field_86_raw": false
  },
  {
    "id": "646358d672945300282fbddd",
    "field_30": "<span class=\"64478ad4fd654a00275108b6\">Tenant</span>",
    "field_30_raw": [
      {
        "id": "64478ad4fd654a00275108b6",
        "identifier": "Tenant"
      }
    ],
    "field_52": "<span class=\"646358554004c60028bf7aae\">Tenant Two</span>",
    "field_52_raw": [
      {
        "id": "646358554004c60028bf7aae",
        "identifier": "Tenant Two"
      }
    ],
    "field_3": "Mr Tenant Two",
    "field_3_raw": "Mr Tenant Two",
    "field_23": "88 Láng Hạ<br />Láng Hạ, Hà Nội <br />Vietnam",
    "field_23_raw": {
      "street": "88 Láng Hạ",
      "street2": null,
      "city": "Láng Hạ",
      "state": "Hà Nội",
      "zip": null,
      "country": "Vietnam",
      "longitude": 105.81409,
      "latitude": 21.01497,
      "full": "88 Láng Hạ Láng Hạ, Hà Nội  Vietnam"
    },
    "field_24": "",
    "field_24_raw": "",
    "field_25": "",
    "field_25_raw": "",
    "field_61": "Mr Tenant Two Tenant",
    "field_61_raw": "Mr Tenant Two Tenant",
    "field_86": "No",
    "field_86_raw": false
  }
]

Thank you!

Hi @paul2000, I am not sure I fully understand your requirements based on your description, your example data only includes two items with different values in field_30_raw, so I don’t quite understand how you want to join this data.

Perhaps you can confirm how the end result should look based on the input data you have provided?

I guess I need a function to split out the json by the identifier which is nested under field_30_raw

This field while being an array only has a single value for me in each of your items. If you want to get both the id and the identifier in their own fields you can achieve this using a Set node:

In a workflow this would look like so:

1 Like

Hi @MutedJam,

Sorry I was not very clear. In the meantime my son worked it out for me. Here is the solution:

$input.item.json.tenants = "";
$input.item.json.field_3_raw.forEach(function(field_3_raw) {
    $input.item.json.tenants += field_3_raw + " "
  });

return $input.item;

We have this code in a code node and then a Item List Concatenate Parties node in front of it.

Thank you!

3 Likes

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