Item Lists Split out Items - Error

Describe the issue/error/question

I try to list the officers of UK companies from companies house data. Each company can have several Officers.


{
"officers":
[
{
"links":
{
"self":
"/company/SC606050/appointments/BhjxL7_xEYisSpsJxFnnuCg2-KI",
"officer":
{
"appointments":
"/officers/58W4ktOEXS81o39P1gR0gGB3Fmg/appointments"
}
},
"country_of_residence":
"Scotland",
"date_of_birth":
{
"year":
1972,
"month":
7
},
"nationality":
"British",
"officer_role":
"director",
"occupation":
"Director",
"appointed_on":
"2018-08-22",
"name":
"WIGHAM, Timothy Walter",
"address":
{
"country":
"Scotland",
"premises":
"26 Polmuir Road",
"locality":
"Aberdeen",
"postal_code":
"AB11 7SY"
}
},
{
"officer_role":
"director",
"nationality":
"Dutch",
"date_of_birth":
{
"year":
1974,
"month":
7
},
"links":
{
"officer":
{
"appointments":
"/officers/n2uRM6L3O_yLRz_BA8UoHDExLb0/appointments"
},
"self":
"/company/SC606050/appointments/CkElVaAlHahzh0gtBTjVbm08Qys"
},
"country_of_residence":
"Scotland",
"address":
{
"locality":
"Aberdeen",
"postal_code":
"AB11 7SY",
"premises":
"26 Polmuir Road",
"country":
"Scotland"
},
"name":
"WIGHAM DE BOER, Aafke",
"occupation":
"Director",
"appointed_on":
"2018-08-22"
}
]
},

I need to split the officers into separate items and afterwards the other attributes like address into separate fields.

I get the error “ERROR: Couldn’t find the field ’ [object Object]’ in the input data”

What is the error message (if any)?

Please share the workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.198.2
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process [own(default), main]:
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: desktop app mac

Hi @Hendrik_Nehnes

Welcome to the community.

You are settings the value of that field here with the expression. Set it to “fixed” and just fill in the actual name of the field. :slight_smile:

1 Like

Hi BramKn,

thank you for your response. I tried it out but still get an error.

Check this thread in which I had the same issue (resolved by @MutedJam ):

Basically, one of the previous intput items is empty (the error is slightly misleading, however it is also accurate because technically a null input entry in a list of items does not have the field present)

So you will need to add some logic before the input to filter out the empty items (you can use an IF node for this).

2 Likes

Thank you @joeldeteves

that solved the issue

2 Likes

However, also when I try to filter our the empty ones using IF, I get a similar error.

The error is Cannot read properties of undefined (reading ‘0’)

JSON is:


[
{
"officers":
[
{
"occupation":
"Self Employed",
"officer_role":
"director",
"links":
{
"self":
"/company/14413082/appointments/oYUDk1uRGD9HEGVBK6X6HAUW0pU",
"officer":
{
"appointments":
"/officers/KWyqJqujf6br7xiGE5AfyBH20wM/appointments"
}
},
"country_of_residence":
"England",
"name":
"SHAH, Reema",
"appointed_on":
"2022-10-12",
"nationality":
"British",
"address":
{
"locality":
"Guildford",
"address_line_1":
"Bridge Street",
"postal_code":
"GU1 4RY",
"country":
"England",
"premises":
5
},
"date_of_birth":
{
"year":
1996,
"month":
5
}
}
]
},
{
},
{
"officers":
[
{
"country_of_residence":
"United Kingdom",
"name":
"CONWAY, Liam",
"occupation":
"Company Director",
"nationality":
"British",
"date_of_birth":
{
"year":
1991,
"month":
10
},
"officer_role":
"director",
"links":
{
"officer":
{
"appointments":
"/officers/w-qgajO7trSdfDaQRo7Vs0e8ZXo/appointments"
},
"self":
"/company/11399177/appointments/ZThePtwN7hEIBa-zPCJDLELkJSc"
},
"address":
{
"country":
"United Kingdom",
"locality":
"Romiley",
"address_line_1":
"Hatherlow House",
"address_line_2":
"Hatherlow",
"premises":
"The Studio",
"postal_code":
"SK6 3DY"
},
"appointed_on":
"2018-06-05"
}
]
},
{
"officers":
[
{
"date_of_birth":
{
"month":
1,
"year":
1968
},
"nationality":
"American",
"occupation":
"Entrepreneur",
"appointed_on":
"2018-12-28",
"officer_role":
"director",
"links":
{
"officer":
{
"appointments":
"/officers/_dwE2Oj68PxqrkzdriA4wFn-qaY/appointments"
},
"self":
"/company/11743365/appointments/e6j3X88Nc96VZv80gvOZ4TIEi6M"
},
"address":
{
"country":
"United Kingdom",
"premises":
"372 Old Street",
"address_line_1":
"335 Rosden House",
"postal_code":
"EC1V 9LT",
"locality":
"London"
},
"country_of_residence":
"United Kingdom",
"name":
"MASCARENHAS, Phillip Jerome"
}
]
}
]

your first and second screenshot where the input is shown are different why is that?

nvm it is solved. missed that.

I don’t think the built in comparison operator for “empty” will work for this. You’ll need to do a little “expression-fu.”

One way to do this is with an expression that checks to see if the field does in fact, exist:

{{ $json["officers"] ? true : false }}

2 Likes

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