# How to dynamically set a value based on another key-value

**URL:** <https://forum.alumio.com/t/how-to-dynamically-set-a-value-based-on-another-key-value/617>\
**Category:** Data Transformers\
**Tags:** data-transformer\
**Created:** [May 31, 2023, 8:28am UTC](https://forum.alumio.com/t/how-to-dynamically-set-a-value-based-on-another-key-value/617 "2023-05-31T08:28:30Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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 31, 2023, 10:01am UTC](https://forum.alumio.com/t/how-to-dynamically-set-a-value-based-on-another-key-value/617/2 "2023-05-31T10:01:46Z")

</div>

I found a solution based on [this former post](https://forum.alumio.com/t/copy-data-between-each-other-by-keys/517/3). By rewriting the example object to an array containing the key-value for comparison.

```json
{
  "options": [
    {
      "color": "red",
      "emotion": "sad",
      "condition2": "bad"
    },
    {
      "color": "green",
      "emotion": "happy",
      "condition2": "good"
    },
    {
      "color": "yellow",
      "emotion": "meh",
      "condition2": "neutral"
    }
  ],
  "condition1": "good"
}

```

Then Recursively copy the outer condition into each of the array objects and finally make a value setter to copy the matching object using jmespath:  
myCondition.string = `&{options[?condition2 == condition1]}`

Still it would be interesting to know if this can be done directly without the recursive copying.

---

_[View the full topic](https://forum.alumio.com/t/how-to-dynamically-set-a-value-based-on-another-key-value/617)._
