How to select specific fileds for objects in a list for the HTTP request tool?

Describe the problem/error/question

i’m wondering if there is a spesial syntax for HTTP request tool for the AI Agent node with an Optimized Response option for selecting only specific fields of objects that are in a list.

What is the error message (if any)?

no errors

Please share your workflow

Share the output returned by the last node

it works well with objects themselves and fields of one specific object but not if these objects are in a list.
let’s say I have the following JSON response

{
  "list_of_obj": [
    {"obj":{"p1":"v1","p2":"v2"}},
    {"obj":{"p1":"v1","p2":"v2"}},
    {"obj":{"p1":"v1","p2":"v2"}}
  ],
  "placeholder": {"random_int":{random_int}}
}

and i want to keep only the p1 field for every obj in list_of_obj

{
  "list_of_obj": [
    {"obj":{"p1":"v1"}},
    {"obj":{"p1":"v1"}},
    {"obj":{"p1":"v1"}}
  ]
}

is there a way i can do so?

i’ve tried to do it different ways but only discovered it works like this list_of_obj[0].obj.p1
but it means i need to hardcode the number of the object i expect and this is not good because the number can varray :frowning:

Information on your n8n setup

  • n8n version: 1.85.4

If all you need is the p1 values, you can use map() to create a new array with just those values like this:
list_of_obj.map(item => item.obj.p1)

thanks, but it doesn’t seem that js is working here. :frowning:
i also tried other list methods but with no success

You have to make this an expression:

I can’t give you a full course on JavaScript here though, that’s what you’ll have to look into :wink:

hmm… i also tried to solve this with Expressions, but I cannot understand how I can predefine the expression for output that hasn’t happened already.

is there some variable i can refer to?

seems like i can only reffer to $input here or other nodes’ outputs but it cannot help me to work with output of this tool…

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