# Node transformer tester

**URL:** <https://forum.alumio.com/t/node-transformer-tester/599>\
**Category:** Incoming Configuration\
**Tags:** data-transformer\
**Created:** [May 18, 2023, 5:28am UTC](https://forum.alumio.com/t/node-transformer-tester/599 "2023-05-18T05:28:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kjetil](https://forum.alumio.com/letter_avatar_proxy/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.alumio.com/u/kjetil)\
**Post date:** [May 18, 2023, 5:28am UTC](https://forum.alumio.com/t/node-transformer-tester/599/1 "2023-05-18T05:28:09Z")

</div>

I try to get friends with the node transformer so I made a small test transformer for that using basically two different input objects: a simple array {“a”:[1,2,3]} and an object array {“a”:[{“b”:1},{“b”:2},{“b”:3}]}.  
Now since my intention is to use HTTP transformer to make request on each item in the array, I use a merge transformer which should write the result to a separate object, “result”:.  
Using a value setter inside the merge transformer just to test how things go. Expected to get “result”:[{“b”:“processed 1”},{“b”:“processed 2”},{“b”:“processed 3”}].  
Anyone can help me out on this? I have seen the videos that I found on this, but somehow haven’t figured this out - here’s my test node transformer.  
[export\_20230518080706.ndjson](https://forum.alumio.com/uploads/short-url/tDcsA6tQ6wBiCRGCZCLs0DSOSeZ.ndjson) (2.3 KB)

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [May 22, 2023, 12:25pm UTC](https://forum.alumio.com/t/node-transformer-tester/599/2 "2023-05-22T12:25:58Z")

</div>

Hi @kjetil

We checked the exported configurations and found out that you used the “Node transformer” prototype. Unfortunately, the prototype doesn’t work as expected at the moment. You should use an entity transformer called “Node, transform nodes”, which is in the same level as “Data, transform data using mappers and conditions”.

In addition, “Node, transform nodes” **can only be used** to loop through an array of objects or an associated array of objects, such as below.

```auto
// Array of objects
{
  "options": [
    {
      "id": "123"
    },
    {
      "id": "123"
    },
    {
      "id": "123"
    }
  ]
}

// Associated array of objects
{
  "options": [
    "123": {
      "id": "123"
    },
    "456": {
      "id": "123"
    },
    "789": {
      "id": "123"
    }
  ]
}

```

It **cannot** loop through an array such as below.

```auto
{
  "options": [
    "123",
    "456",
    "789"
  ]
}

```

If you need to loop to the above array using the “Node, transform nodes” entity transformer, you can map the `options` property into an array of objects using the below “Move using a pattern” transformer.

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/da80f998f98ce0a64070dbfa80c6d1d106e8b0b4.png)

Inside the node transformer, you cannot read or write any properties outside the array it is looping. For example, if you use the “Node, transform nodes” to loop through the `options` array, you will not be able to read or write any properties outside of the `options` array to write or create a new property called `result`.

For instance, you merge an HTTP transformer result to a property named `result`, so each object has a `result` property such as below.

```auto
{
  "id": "1",
  "options": [
    {
      "id": "123",
      "result": {
        "userId": 1,
        "id": 1,
        "title": "delectus aut autem",
        "completed": false
      }
    },
    {
      "id": "345",
      "result": {
        "userId": 1,
        "id": 1,
        "title": "delectus aut autem",
        "completed": false
      }
    },
    {
      "id": "456",
      "result": {
        "userId": 1,
        "id": 1,
        "title": "delectus aut autem",
        "completed": false
      }
    }
  ]
}

```

You can then copy the result from each object to a property called `result` in the root of your entity using the below transformer.

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/1X/ac09ec77750fc61c00cabb0082589d21f47747f4.png)

Please give it a try and let us know if you have any further questions.

---

<div class="post-metadata">

**Author:** ![kjetil](https://forum.alumio.com/letter_avatar_proxy/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.alumio.com/u/kjetil)\
**Post date:** [May 23, 2023, 5:54am UTC](https://forum.alumio.com/t/node-transformer-tester/599/3 "2023-05-23T05:54:17Z")

</div>

Thank you for this thorough explanation, it helps a lot! In my case, since the node transformer does not read from root, I need to copy root data (a product ID) _into_ each of those nodes before iterating over them. Would you have advice on how to do that too?  
Something like `$.options[*].root_id = $.ID`.  
Edit: I found the answer to this - found the data transformer named “ **Recursively copy values to children** ” which does the trick.

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [May 23, 2023, 12:48pm UTC](https://forum.alumio.com/t/node-transformer-tester/599/4 "2023-05-23T12:48:41Z")

</div>

You are correct that you can use [Recursively copy values to children](https://forum.alumio.com/t/recursively-copy-values-to-children/287) to copy a value to all objects in an array.
