Code Python list item

Hi,

Just a little question. I am stuck on a little thing.
I would like to extract all the IP addresses and some information from a json
for exemple
IPaddress continentCode continentName countryCode
8.8.8.8 NA North America US
1.2.3.4 OC Oceania AU

but it doesnt work as expected.
Could you please help me?
Many thanks

I have the following code

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @herrT15,

Do you need to use Python for it? Looking at your code you are looping your items then setting str to your value and returning it on the first loop instead of appending to your array and returning it later.

Hello, Thanks for your reply!
Python is not mandatory

Hey @herrT15,

Perfect, In that case did you work it out based on what I previously sent?

yes! did it with something like

for item in data:
for key, value in item.items():
result_list.append({
“IPaddress”: key,
“continentCode”: value.get(“continentCode”, “”),
“countryCode”: value.get(“countryCode”, “”),
“countryName”: value.get(“countryName”, “”)
})
# Now you can use the result_list as needed

return result_list

but one last thing how to collect the json from a previous node? in order to implement json_data =?

regarding the documentation :
Shorthand for _input.item.json. Incoming JSON data from a node. Refer to Data structure for information on item structure. Available when you set Mode to Run Once for Each Item.

but the following error occured
ERROR: TypeError(f’the JSON object must be str, bytes or bytearray, ’ TypeError: the JSON object must be str, bytes or bytearray, not JsProxy

Hey @herrT15,

Try the workflow below…

1 Like

You rock! thanks a lot

1 Like

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