# Lookup in two objects and match by key

**URL:** <https://forum.alumio.com/t/lookup-in-two-objects-and-match-by-key/1317>\
**Category:** Data Transformers\
**Created:** [September 6, 2024, 12:42pm UTC](https://forum.alumio.com/t/lookup-in-two-objects-and-match-by-key/1317 "2024-09-06T12:42:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoeri](https://forum.alumio.com/letter_avatar_proxy/v4/letter/y/dc4da7/32.png) [@yoeri](https://forum.alumio.com/u/yoeri)\
**Post date:** [September 6, 2024, 12:42pm UTC](https://forum.alumio.com/t/lookup-in-two-objects-and-match-by-key/1317/1 "2024-09-06T12:42:14Z")

</div>

Hello,

I’m trying to copy/move a value from one object to another when they share the same key.

For example this is my data:

```auto
{
  "metafields": [
    {
      "id": null,
      "key": "kilometers",
      "type": "number_integer",
      "value": "15",
      "namespace": "custom"
    },
    {
      "id": null,
      "key": "model",
      "type": "single_line_text_field",
      "value": "A1",
      "namespace": "custom"
    }
  ],
  "shopifyProduct": {
    "metafields": {
      "nodes": [
        {
          "id": "gid://shopify/Metafield/36311756865816",
          "key": "model",
          "type": "single_line_text_field",
          "value": "A1",
          "namespace": "custom"
        },
        {
          "id": "gid://shopify/Metafield/36312200544536",
          "key": "kilometers",
          "type": "number_integer",
          "value": "25",
          "namespace": "custom"
        },
        {
          "id": "gid://shopify/Metafield/36312579801368",
          "key": "transmissie",
          "type": "single_line_text_field",
          "value": "Automaat",
          "namespace": "custom"
        }
      ]
    }
  }
}

```

When a key from “metafields” and “shopifyProduct.metafields.nodes” match, the value from "“shopifyProduct.metafields.nodes” should be copied to the corresponding object in “metafields”.

The above example should result in:

```auto
{
  "metafields": [
    {
      "id": "gid://shopify/Metafield/36312200544536",
      "key": "kilometers",
      "type": "number_integer",
      "value": "15",
      "namespace": "custom"
    },
    {
      "id": "gid://shopify/Metafield/36311756865816",
      "key": "model",
      "type": "single_line_text_field",
      "value": "A1",
      "namespace": "custom"
    }
  ],
  "shopifyProduct": {
    "metafields": {
      "nodes": [
        {
          "id": "gid://shopify/Metafield/36311756865816",
          "key": "model",
          "type": "single_line_text_field",
          "value": "A1",
          "namespace": "custom"
        },
        {
          "id": "gid://shopify/Metafield/36312200544536",
          "key": "kilometers",
          "type": "number_integer",
          "value": "25",
          "namespace": "custom"
        },
        {
          "id": "gid://shopify/Metafield/36312579801368",
          "key": "transmissie",
          "type": "single_line_text_field",
          "value": "Automaat",
          "namespace": "custom"
        }
      ]
    }
  }
}

```

We cannot trust on the order of the items in both objects because they can be dynamic. That is why we need to check on the key, that should be the same.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mko](https://forum.alumio.com/user_avatar/forum.alumio.com/mko/32/1735_2.png) [@mko](https://forum.alumio.com/u/mko)\
**Post date:** [September 9, 2024, 7:40am UTC](https://forum.alumio.com/t/lookup-in-two-objects-and-match-by-key/1317/2 "2024-09-09T07:40:30Z")

</div>

Hi @yoeri

Here is one example to fix this.  
Try importing it and have a look.

I hope it helps you!

[testing-transformer\_transformer.ndjson](https://forum.alumio.com/uploads/short-url/7imvPXfel2CXLL0REer0Qxf8VkU.ndjson) (1015 Bytes)

---

<div class="post-metadata">

**Author:** ![yoeri](https://forum.alumio.com/letter_avatar_proxy/v4/letter/y/dc4da7/32.png) [@yoeri](https://forum.alumio.com/u/yoeri)\
**Post date:** [September 9, 2024, 11:24am UTC](https://forum.alumio.com/t/lookup-in-two-objects-and-match-by-key/1317/3 "2024-09-09T11:24:38Z")

</div>

Hi @mko,

Thank you for your reply. It does exactly what I want 🙂
